Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
79859ebc
Commit
79859ebc
authored
Jul 25, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15145 from alalek:fix_15127
parents
b10ec8ef
5691d998
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
0 deletions
+54
-0
persistence_json.cpp
modules/core/src/persistence_json.cpp
+12
-0
persistence_xml.cpp
modules/core/src/persistence_xml.cpp
+21
-0
persistence_yml.cpp
modules/core/src/persistence_yml.cpp
+21
-0
No files found.
modules/core/src/persistence_json.cpp
View file @
79859ebc
...
@@ -296,6 +296,8 @@ public:
...
@@ -296,6 +296,8 @@ public:
while
(
is_eof
==
false
&&
is_completed
==
false
)
while
(
is_eof
==
false
&&
is_completed
==
false
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
switch
(
*
ptr
)
switch
(
*
ptr
)
{
{
/* comment */
/* comment */
...
@@ -381,6 +383,7 @@ public:
...
@@ -381,6 +383,7 @@ public:
if
(
is_eof
||
!
is_completed
)
if
(
is_eof
||
!
is_completed
)
{
{
ptr
=
fs
->
bufferStart
();
ptr
=
fs
->
bufferStart
();
CV_Assert
(
ptr
);
*
ptr
=
'\0'
;
*
ptr
=
'\0'
;
fs
->
setEof
();
fs
->
setEof
();
if
(
!
is_completed
)
if
(
!
is_completed
)
...
@@ -392,6 +395,9 @@ public:
...
@@ -392,6 +395,9 @@ public:
char
*
parseKey
(
char
*
ptr
,
FileNode
&
collection
,
FileNode
&
value_placeholder
)
char
*
parseKey
(
char
*
ptr
,
FileNode
&
collection
,
FileNode
&
value_placeholder
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
if
(
*
ptr
!=
'"'
)
if
(
*
ptr
!=
'"'
)
CV_PARSE_ERROR_CPP
(
"Key must start with
\'\"\'
"
);
CV_PARSE_ERROR_CPP
(
"Key must start with
\'\"\'
"
);
...
@@ -430,6 +436,9 @@ public:
...
@@ -430,6 +436,9 @@ public:
char
*
parseValue
(
char
*
ptr
,
FileNode
&
node
)
char
*
parseValue
(
char
*
ptr
,
FileNode
&
node
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid value input"
);
ptr
=
skipSpaces
(
ptr
);
ptr
=
skipSpaces
(
ptr
);
if
(
!
ptr
||
!*
ptr
)
if
(
!
ptr
||
!*
ptr
)
CV_PARSE_ERROR_CPP
(
"Unexpected End-Of-File"
);
CV_PARSE_ERROR_CPP
(
"Unexpected End-Of-File"
);
...
@@ -817,6 +826,9 @@ public:
...
@@ -817,6 +826,9 @@ public:
bool
parse
(
char
*
ptr
)
bool
parse
(
char
*
ptr
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
ptr
=
skipSpaces
(
ptr
);
ptr
=
skipSpaces
(
ptr
);
if
(
!
ptr
||
!*
ptr
)
if
(
!
ptr
||
!*
ptr
)
return
false
;
return
false
;
...
...
modules/core/src/persistence_xml.cpp
View file @
79859ebc
...
@@ -360,6 +360,9 @@ public:
...
@@ -360,6 +360,9 @@ public:
char
*
skipSpaces
(
char
*
ptr
,
int
mode
)
char
*
skipSpaces
(
char
*
ptr
,
int
mode
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
int
level
=
0
;
int
level
=
0
;
for
(;;)
for
(;;)
...
@@ -441,6 +444,9 @@ public:
...
@@ -441,6 +444,9 @@ public:
char
*
parseValue
(
char
*
ptr
,
FileNode
&
node
)
char
*
parseValue
(
char
*
ptr
,
FileNode
&
node
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
FileNode
new_elem
;
FileNode
new_elem
;
bool
have_space
=
true
;
bool
have_space
=
true
;
int
value_type
=
node
.
type
();
int
value_type
=
node
.
type
();
...
@@ -456,6 +462,8 @@ public:
...
@@ -456,6 +462,8 @@ public:
(
c
==
'<'
&&
ptr
[
1
]
==
'!'
&&
ptr
[
2
]
==
'-'
)
)
(
c
==
'<'
&&
ptr
[
1
]
==
'!'
&&
ptr
[
2
]
==
'-'
)
)
{
{
ptr
=
skipSpaces
(
ptr
,
0
);
ptr
=
skipSpaces
(
ptr
,
0
);
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
have_space
=
true
;
have_space
=
true
;
c
=
*
ptr
;
c
=
*
ptr
;
}
}
...
@@ -502,6 +510,8 @@ public:
...
@@ -502,6 +510,8 @@ public:
{
{
ptr
=
fs
->
parseBase64
(
ptr
,
0
,
new_elem
);
ptr
=
fs
->
parseBase64
(
ptr
,
0
,
new_elem
);
ptr
=
skipSpaces
(
ptr
,
0
);
ptr
=
skipSpaces
(
ptr
,
0
);
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
}
}
ptr
=
parseTag
(
ptr
,
key2
,
type_name
,
tag_type
);
ptr
=
parseTag
(
ptr
,
key2
,
type_name
,
tag_type
);
...
@@ -645,6 +655,9 @@ public:
...
@@ -645,6 +655,9 @@ public:
char
*
parseTag
(
char
*
ptr
,
std
::
string
&
tag_name
,
char
*
parseTag
(
char
*
ptr
,
std
::
string
&
tag_name
,
std
::
string
&
type_name
,
int
&
tag_type
)
std
::
string
&
type_name
,
int
&
tag_type
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid tag input"
);
if
(
*
ptr
==
'\0'
)
if
(
*
ptr
==
'\0'
)
CV_PARSE_ERROR_CPP
(
"Unexpected end of the stream"
);
CV_PARSE_ERROR_CPP
(
"Unexpected end of the stream"
);
...
@@ -702,6 +715,8 @@ public:
...
@@ -702,6 +715,8 @@ public:
if
(
*
ptr
!=
'='
)
if
(
*
ptr
!=
'='
)
{
{
ptr
=
skipSpaces
(
ptr
,
CV_XML_INSIDE_TAG
);
ptr
=
skipSpaces
(
ptr
,
CV_XML_INSIDE_TAG
);
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid attribute"
);
if
(
*
ptr
!=
'='
)
if
(
*
ptr
!=
'='
)
CV_PARSE_ERROR_CPP
(
"Attribute name should be followed by
\'
=
\'
"
);
CV_PARSE_ERROR_CPP
(
"Attribute name should be followed by
\'
=
\'
"
);
}
}
...
@@ -740,6 +755,8 @@ public:
...
@@ -740,6 +755,8 @@ public:
if
(
c
!=
'>'
)
if
(
c
!=
'>'
)
{
{
ptr
=
skipSpaces
(
ptr
,
CV_XML_INSIDE_TAG
);
ptr
=
skipSpaces
(
ptr
,
CV_XML_INSIDE_TAG
);
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
c
=
*
ptr
;
c
=
*
ptr
;
}
}
...
@@ -781,6 +798,8 @@ public:
...
@@ -781,6 +798,8 @@ public:
// CV_XML_INSIDE_TAG is used to prohibit leading comments
// CV_XML_INSIDE_TAG is used to prohibit leading comments
ptr
=
skipSpaces
(
ptr
,
CV_XML_INSIDE_TAG
);
ptr
=
skipSpaces
(
ptr
,
CV_XML_INSIDE_TAG
);
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
if
(
memcmp
(
ptr
,
"<?xml"
,
5
)
!=
0
)
// FIXIT ptr[1..] - out of bounds read without check
if
(
memcmp
(
ptr
,
"<?xml"
,
5
)
!=
0
)
// FIXIT ptr[1..] - out of bounds read without check
CV_PARSE_ERROR_CPP
(
"Valid XML should start with
\'
<?xml ...?>
\'
"
);
CV_PARSE_ERROR_CPP
(
"Valid XML should start with
\'
<?xml ...?>
\'
"
);
...
@@ -791,6 +810,8 @@ public:
...
@@ -791,6 +810,8 @@ public:
while
(
ptr
&&
*
ptr
!=
'\0'
)
while
(
ptr
&&
*
ptr
!=
'\0'
)
{
{
ptr
=
skipSpaces
(
ptr
,
0
);
ptr
=
skipSpaces
(
ptr
,
0
);
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
if
(
*
ptr
!=
'\0'
)
if
(
*
ptr
!=
'\0'
)
{
{
...
...
modules/core/src/persistence_yml.cpp
View file @
79859ebc
...
@@ -330,6 +330,9 @@ public:
...
@@ -330,6 +330,9 @@ public:
char
*
skipSpaces
(
char
*
ptr
,
int
min_indent
,
int
max_comment_indent
)
char
*
skipSpaces
(
char
*
ptr
,
int
min_indent
,
int
max_comment_indent
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
for
(;;)
for
(;;)
{
{
while
(
*
ptr
==
' '
)
while
(
*
ptr
==
' '
)
...
@@ -374,6 +377,9 @@ public:
...
@@ -374,6 +377,9 @@ public:
bool
getBase64Row
(
char
*
ptr
,
int
indent
,
char
*
&
beg
,
char
*
&
end
)
bool
getBase64Row
(
char
*
ptr
,
int
indent
,
char
*
&
beg
,
char
*
&
end
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
beg
=
end
=
ptr
=
skipSpaces
(
ptr
,
0
,
INT_MAX
);
beg
=
end
=
ptr
=
skipSpaces
(
ptr
,
0
,
INT_MAX
);
if
(
!
ptr
||
!*
ptr
)
if
(
!
ptr
||
!*
ptr
)
return
false
;
// end of file
return
false
;
// end of file
...
@@ -394,6 +400,9 @@ public:
...
@@ -394,6 +400,9 @@ public:
char
*
parseKey
(
char
*
ptr
,
FileNode
&
map_node
,
FileNode
&
value_placeholder
)
char
*
parseKey
(
char
*
ptr
,
FileNode
&
map_node
,
FileNode
&
value_placeholder
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
char
c
;
char
c
;
char
*
endptr
=
ptr
-
1
,
*
saveptr
;
char
*
endptr
=
ptr
-
1
,
*
saveptr
;
...
@@ -422,6 +431,9 @@ public:
...
@@ -422,6 +431,9 @@ public:
char
*
parseValue
(
char
*
ptr
,
FileNode
&
node
,
int
min_indent
,
bool
is_parent_flow
)
char
*
parseValue
(
char
*
ptr
,
FileNode
&
node
,
int
min_indent
,
bool
is_parent_flow
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
char
*
endptr
=
0
;
char
*
endptr
=
0
;
char
c
=
ptr
[
0
],
d
=
ptr
[
1
];
char
c
=
ptr
[
0
],
d
=
ptr
[
1
];
int
value_type
=
FileNode
::
NONE
;
int
value_type
=
FileNode
::
NONE
;
...
@@ -508,6 +520,8 @@ public:
...
@@ -508,6 +520,8 @@ public:
*
endptr
=
d
;
*
endptr
=
d
;
ptr
=
skipSpaces
(
endptr
,
min_indent
,
INT_MAX
);
ptr
=
skipSpaces
(
endptr
,
min_indent
,
INT_MAX
);
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
c
=
*
ptr
;
c
=
*
ptr
;
...
@@ -634,6 +648,8 @@ public:
...
@@ -634,6 +648,8 @@ public:
FileNode
elem
;
FileNode
elem
;
ptr
=
skipSpaces
(
ptr
,
new_min_indent
,
INT_MAX
);
ptr
=
skipSpaces
(
ptr
,
new_min_indent
,
INT_MAX
);
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
if
(
*
ptr
==
'}'
||
*
ptr
==
']'
)
if
(
*
ptr
==
'}'
||
*
ptr
==
']'
)
{
{
if
(
*
ptr
!=
d
)
if
(
*
ptr
!=
d
)
...
@@ -647,6 +663,8 @@ public:
...
@@ -647,6 +663,8 @@ public:
if
(
*
ptr
!=
','
)
if
(
*
ptr
!=
','
)
CV_PARSE_ERROR_CPP
(
"Missing , between the elements"
);
CV_PARSE_ERROR_CPP
(
"Missing , between the elements"
);
ptr
=
skipSpaces
(
ptr
+
1
,
new_min_indent
,
INT_MAX
);
ptr
=
skipSpaces
(
ptr
+
1
,
new_min_indent
,
INT_MAX
);
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
}
}
if
(
struct_type
==
FileNode
::
MAP
)
if
(
struct_type
==
FileNode
::
MAP
)
...
@@ -746,6 +764,9 @@ public:
...
@@ -746,6 +764,9 @@ public:
bool
parse
(
char
*
ptr
)
bool
parse
(
char
*
ptr
)
{
{
if
(
!
ptr
)
CV_PARSE_ERROR_CPP
(
"Invalid input"
);
bool
first
=
true
;
bool
first
=
true
;
bool
ok
=
true
;
bool
ok
=
true
;
FileNode
root_collection
(
fs
->
getFS
(),
0
,
0
);
FileNode
root_collection
(
fs
->
getFS
(),
0
,
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment