From bd0bc5af590bb434f50dd0392696916a5f67b146 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 18 May 2026 13:35:38 +0300 Subject: [PATCH] Fixed data overflow issue when int64 value is interpreted as float/double. --- modules/core/src/persistence.cpp | 5 +++-- modules/core/test/test_io.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 673a4f8a80..4f0cf2868a 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -2410,7 +2410,7 @@ FileNode::operator float() const if( type == INT ) { - return (float)readInt(p); + return (float)readLong(p); } else if( type == REAL ) { @@ -2431,7 +2431,7 @@ FileNode::operator double() const if( type == INT ) { - return (double)readInt(p); + return (double)readLong(p); } else if( type == REAL ) { @@ -2442,6 +2442,7 @@ FileNode::operator double() const } double FileNode::real() const { return double(*this); } + std::string FileNode::string() const { const uchar* p = ptr(); diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index e0417244a1..b0aeda4025 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -2155,6 +2155,7 @@ TEST(Core_InputOutput, FileStorage_int64_26829) "IntMax: 2147483647\n" "String4: string4\n" "Int64Max: 9223372036854775807\n" + "Int64Reg: 2147484671\n" "String5: string5\n"; FileStorage fs(content, FileStorage::READ | FileStorage::MEMORY); @@ -2197,6 +2198,14 @@ TEST(Core_InputOutput, FileStorage_int64_26829) fs["Int64Max"] >> value; EXPECT_EQ(value, INT64_MAX); + + fs["Int64Reg"] >> value; + EXPECT_EQ(value, 2147484671); // C++ INT_MAX +1024 + } + + { + double value = fs["Int64Reg"].real(); + EXPECT_EQ(value, 2147484671); // C++ INT_MAX +1024 } }