Commit 5dd3e605 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #15868 from alalek:issue_15857

parents 3d47e043 f42d5399
...@@ -578,10 +578,14 @@ public: ...@@ -578,10 +578,14 @@ public:
sz = (int)(ptr - beg); sz = (int)(ptr - beg);
if( sz > 0 ) if( sz > 0 )
{ {
if (i + sz >= CV_FS_MAX_LEN)
CV_PARSE_ERROR_CPP("string is too long");
memcpy(buf + i, beg, sz); memcpy(buf + i, beg, sz);
i += sz; i += sz;
} }
ptr++; ptr++;
if (i + 1 >= CV_FS_MAX_LEN)
CV_PARSE_ERROR_CPP("string is too long");
switch ( *ptr ) switch ( *ptr )
{ {
case '\\': case '\\':
...@@ -605,6 +609,8 @@ public: ...@@ -605,6 +609,8 @@ public:
sz = (int)(ptr - beg); sz = (int)(ptr - beg);
if( sz > 0 ) if( sz > 0 )
{ {
if (i + sz >= CV_FS_MAX_LEN)
CV_PARSE_ERROR_CPP("string is too long");
memcpy(buf + i, beg, sz); memcpy(buf + i, beg, sz);
i += sz; i += sz;
} }
...@@ -620,6 +626,8 @@ public: ...@@ -620,6 +626,8 @@ public:
sz = (int)(ptr - beg); sz = (int)(ptr - beg);
if( sz > 0 ) if( sz > 0 )
{ {
if (i + sz >= CV_FS_MAX_LEN)
CV_PARSE_ERROR_CPP("string is too long");
memcpy(buf + i, beg, sz); memcpy(buf + i, beg, sz);
i += sz; i += sz;
} }
......
...@@ -627,6 +627,8 @@ public: ...@@ -627,6 +627,8 @@ public:
c = '\"'; c = '\"';
else else
{ {
if (len + 2 + i >= CV_FS_MAX_LEN)
CV_PARSE_ERROR_CPP("string is too long");
memcpy( strbuf + i, ptr-1, len + 2 ); memcpy( strbuf + i, ptr-1, len + 2 );
i += len + 2; i += len + 2;
} }
...@@ -635,9 +637,9 @@ public: ...@@ -635,9 +637,9 @@ public:
CV_PERSISTENCE_CHECK_END_OF_BUFFER_BUG_CPP(); CV_PERSISTENCE_CHECK_END_OF_BUFFER_BUG_CPP();
} }
} }
if (i + 1 >= CV_FS_MAX_LEN)
CV_PARSE_ERROR_CPP("Too long string literal");
strbuf[i++] = c; strbuf[i++] = c;
if( i >= CV_FS_MAX_LEN )
CV_PARSE_ERROR_CPP( "Too long string literal" );
} }
elem->setValue(FileNode::STRING, strbuf, i); elem->setValue(FileNode::STRING, strbuf, i);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment