Before

…lines 1–152 unchanged (152 lines)
153 buff[8+4+1] = 'g';
154 buff[8+4+2] = 'B';
155 buff[8+4+3] = 'I';
156 EXPECT_NO_THROW(img = imdecode(buff, IMREAD_COLOR));
157 EXPECT_TRUE(img.empty());
158}
159
160typedef testing::TestWithParam<string> Imgcodecs_Png_PngSuite;
161
162// Parameterized test for decoding PNG files from the PNGSuite test set
163TEST_P(Imgcodecs_Png_PngSuite, decode)
164{
165 // Construct full paths for the PNG image and corresponding ground truth XML file
…lines 166–595 unchanged (430 lines)

After

…lines 1–153 unchanged (153 lines)
154 buff[8+4+2] = 'B';
155 buff[8+4+3] = 'I';
156 EXPECT_NO_THROW(img = imdecode(buff, IMREAD_COLOR));
157 EXPECT_TRUE(img.empty());
158}
159
160// The program must not crash even when decoding a corrupted APNG image.
161// See https://github.com/opencv/opencv/issues/27744
162#if defined(HAVE_PNG) // APNG is supported only with using libpng
163TEST(Imgcodecs_Png, decode_regression27744)
164{
165 // Create APNG stream
166 Animation anim;
167 for(size_t i = 0 ; i < 3 ; i++) {
168 Mat frame(120, 120, CV_8UC3, Scalar(0,0,0));
169 putText(frame, cv::format("%d", static_cast<int>(i)), Point(5, 28), FONT_HERSHEY_SIMPLEX, .5, Scalar(100, 255, 0, 255), 2);
170 anim.frames.push_back(frame);
171 anim.durations.push_back(30);
172 }
173 bool ret = false;
174 vector<uchar> buff;
175 EXPECT_NO_THROW(ret = imencodeanimation(".png", anim, buff));
176 ASSERT_TRUE(ret) << "imencodeanimation() returns false";
177
178 // Find IDAT chunk
179 const vector<uchar> IDAT = {'I', 'D', 'A', 'T' };
180 std::vector<uchar>::iterator it = std::search(buff.begin(), buff.end(), IDAT.begin(), IDAT.end());
181 ASSERT_FALSE(it == buff.end()) << "IDAT chunk not found";
182
183 // Determine the range to test
184 // APNG stream contains as { len0, len1, len2, len3, 'I', 'D', 'A' 'T', ... }
185 size_t idx = std::distance(buff.begin(), it); // 'I' position
186 size_t len = (buff[idx-4] << 24) + (buff[idx-3] << 16) +
187 (buff[idx-2] << 8) + (buff[idx-1]); // IDAT chunk length
188 idx = idx + 4; // Move to IDAT body
189
190 // Test
191 for(size_t i = 0; i < len; i++, idx++) {
192 vector<uint8_t> work = buff;
193 work[idx] = static_cast<uint8_t>((static_cast<uint32_t>(work[idx]) + 1) & 0xff);
194
195 Mat dst;
196 EXPECT_NO_THROW(dst = imdecode(work, cv::IMREAD_COLOR));
197 if(dst.empty()) {
198 // libpng detects some error, but the program is not crashed. Test is passed.
199 break;
200 }
201 }
202}
203#endif
204
205typedef testing::TestWithParam<string> Imgcodecs_Png_PngSuite;
206
207// Parameterized test for decoding PNG files from the PNGSuite test set
208TEST_P(Imgcodecs_Png_PngSuite, decode)
209{
…lines 210–640 unchanged (431 lines)

Before

translation_unit
comment "// This file is part of OpenCV project."
comment "// It is subject to the license terms in the LICENSE file fo"...
comment "// of this distribution and at http://opencv.org/license.htm"...
preproc_include
#include "#include"
string_literal
" "\""
string_content "test_precomp.hpp"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "test_common.hpp"
" "\""
namespace_definition
namespace "namespace"
namespace_identifier "opencv_test"
declaration_list
{ "{"
namespace_definition
namespace "namespace"
declaration_list
{ "{"
preproc_if
#if "#if"
binary_expression
preproc_defined
defined "defined"
( "("
identifier "HAVE_PNG"
) ")"
|| "||"
preproc_defined
defined "defined"
( "("
identifier "HAVE_SPNG"
) ")"
"\n\n"
function_definition (+224 nodes collapsed)
function_definition (+176 nodes collapsed)
function_definition (+158 nodes collapsed)
comment "// Test OpenCV issue 3075 is solved"
function_definition (+790 nodes collapsed)
comment "// IHDR shall be first."
comment "// See https://github.com/opencv/opencv/issues/27295"
function_definition (+440 nodes collapsed)
type_definition
typedef "typedef"
qualified_identifier
namespace_identifier "testing"
:: "::"
template_type
type_identifier "TestWithParam"
template_argument_list
< "<"
type_descriptor
type_identifier "string"
> ">"
type_identifier "Imgcodecs_Png_PngSuite"
; ";"
comment "// Parameterized test for decoding PNG files from the PNGSui"...
function_definition (+1143 nodes collapsed)
declaration (+769 nodes collapsed)
expression_statement (+21 nodes collapsed)
type_definition
typedef "typedef"
qualified_identifier
namespace_identifier "testing"
:: "::"
template_type
type_identifier "TestWithParam"
template_argument_list
< "<"
type_descriptor
type_identifier "string"
> ">"
type_identifier "Imgcodecs_Png_PngSuite_Gamma"
; ";"
comment "// Parameterized test for decoding PNG files from the PNGSui"...
function_definition (+202 nodes collapsed)
declaration (+63 nodes collapsed)
expression_statement (+21 nodes collapsed)
type_definition
typedef "typedef"
qualified_identifier
namespace_identifier "testing"
:: "::"
template_type
type_identifier "TestWithParam"
template_argument_list
< "<"
type_descriptor
type_identifier "string"
> ">"
type_identifier "Imgcodecs_Png_PngSuite_Corrupted"
; ";"
function_definition (+98 nodes collapsed)
declaration (+84 nodes collapsed)
expression_statement (+21 nodes collapsed)
expression_statement
call_expression
identifier "CV_ENUM"
argument_list
( "("
identifier "PNGStrategy"
, ","
identifier "IMWRITE_PNG_STRATEGY_DEFAULT"
, ","
identifier "IMWRITE_PNG_STRATEGY_FILTERED"
, ","
identifier "IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY"
, ","
identifier "IMWRITE_PNG_STRATEGY_RLE"
, ","
identifier "IMWRITE_PNG_STRATEGY_FIXED"
) ")"
; ";"
expression_statement (+22 nodes collapsed)
type_definition (+32 nodes collapsed)
function_definition (+266 nodes collapsed)
expression_statement (+227 nodes collapsed)
type_definition (+29 nodes collapsed)
function_definition (+199 nodes collapsed)
expression_statement (+159 nodes collapsed)
comment "// See https://github.com/opencv/opencv/issues/27614"
type_definition
typedef "typedef"
qualified_identifier
namespace_identifier "testing"
:: "::"
template_type
type_identifier "TestWithParam"
template_argument_list
< "<"
type_descriptor
primitive_type "int"
> ">"
type_identifier "Imgcodecs_Png_ZLIBBUFFER_SIZE"
; ";"
function_definition (+100 nodes collapsed)
expression_statement (+38 nodes collapsed)
#endif "#endif"
comment "// HAVE_PNG"
} "}"
} "}"
comment "// namespace"

After

translation_unit
comment "// This file is part of OpenCV project."
comment "// It is subject to the license terms in the LICENSE file fo"...
comment "// of this distribution and at http://opencv.org/license.htm"...
preproc_include
#include "#include"
string_literal
" "\""
string_content "test_precomp.hpp"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "test_common.hpp"
" "\""
namespace_definition
namespace "namespace"
namespace_identifier "opencv_test"
declaration_list
{ "{"
namespace_definition
namespace "namespace"
declaration_list
{ "{"
preproc_if
#if "#if"
binary_expression
preproc_defined
defined "defined"
( "("
identifier "HAVE_PNG"
) ")"
|| "||"
preproc_defined
defined "defined"
( "("
identifier "HAVE_SPNG"
) ")"
"\n\n"
function_definition (+224 nodes collapsed)
function_definition (+176 nodes collapsed)
function_definition (+158 nodes collapsed)
comment "// Test OpenCV issue 3075 is solved"
function_definition (+790 nodes collapsed)
comment "// IHDR shall be first."
comment "// See https://github.com/opencv/opencv/issues/27295"
function_definition (+440 nodes collapsed)
comment "// The program must not crash even when decoding a corrupted"...
comment "// See https://github.com/opencv/opencv/issues/27744"
preproc_if
#if "#if"
preproc_defined
defined "defined"
( "("
identifier "HAVE_PNG"
) ")"
comment "// APNG is supported only with using libpng"
"\n"
function_definition
function_declarator
identifier "TEST"
parameter_list
( "("
parameter_declaration
type_identifier "Imgcodecs_Png"
, ","
parameter_declaration
type_identifier "decode_regression27744"
) ")"
compound_statement
{ "{"
comment "// Create APNG stream"
declaration
type_identifier "Animation"
identifier "anim"
; ";"
for_statement
for "for"
( "("
declaration
primitive_type "size_t"
init_declarator
identifier "i"
= "="
number_literal "0"
; ";"
binary_expression
identifier "i"
< "<"
number_literal "3"
; ";"
update_expression
identifier "i"
++ "++"
) ")"
compound_statement
{ "{"
declaration
type_identifier "Mat"
init_declarator
identifier "frame"
argument_list
( "("
number_literal "120"
, ","
number_literal "120"
, ","
identifier "CV_8UC3"
, ","
call_expression
identifier "Scalar"
argument_list
( "("
number_literal "0"
, ","
number_literal "0"
, ","
number_literal "0"
) ")"
) ")"
; ";"
expression_statement
call_expression
identifier "putText"
argument_list
( "("
identifier "frame"
, ","
call_expression
qualified_identifier
namespace_identifier "cv"
:: "::"
identifier "format"
argument_list
( "("
string_literal
" "\""
string_content "%d"
" "\""
, ","
call_expression
template_function
identifier "static_cast"
template_argument_list
< "<"
type_descriptor
primitive_type "int"
> ">"
argument_list
( "("
identifier "i"
) ")"
) ")"
, ","
call_expression
identifier "Point"
argument_list
( "("
number_literal "5"
, ","
number_literal "28"
) ")"
, ","
identifier "FONT_HERSHEY_SIMPLEX"
, ","
number_literal ".5"
, ","
call_expression
identifier "Scalar"
argument_list
( "("
number_literal "100"
, ","
number_literal "255"
, ","
number_literal "0"
, ","
number_literal "255"
) ")"
, ","
number_literal "2"
) ")"
; ";"
expression_statement
call_expression
field_expression
field_expression
identifier "anim"
. "."
field_identifier "frames"
. "."
field_identifier "push_back"
argument_list
( "("
identifier "frame"
) ")"
; ";"
expression_statement
call_expression
field_expression
field_expression
identifier "anim"
. "."
field_identifier "durations"
. "."
field_identifier "push_back"
argument_list
( "("
number_literal "30"
) ")"
; ";"
} "}"
declaration
primitive_type "bool"
init_declarator
identifier "ret"
= "="
false "false"
; ";"
declaration
template_type
type_identifier "vector"
template_argument_list
< "<"
type_descriptor
type_identifier "uchar"
> ">"
identifier "buff"
; ";"
expression_statement
call_expression
identifier "EXPECT_NO_THROW"
argument_list
( "("
assignment_expression
identifier "ret"
= "="
call_expression
identifier "imencodeanimation"
argument_list
( "("
string_literal
" "\""
string_content ".png"
" "\""
, ","
identifier "anim"
, ","
identifier "buff"
) ")"
) ")"
; ";"
expression_statement
binary_expression
call_expression
identifier "ASSERT_TRUE"
argument_list
( "("
identifier "ret"
) ")"
<< "<<"
string_literal
" "\""
string_content "imencodeanimation() returns false"
" "\""
; ";"
comment "// Find IDAT chunk"
declaration
type_qualifier
const "const"
template_type
type_identifier "vector"
template_argument_list
< "<"
type_descriptor
type_identifier "uchar"
> ">"
init_declarator
identifier "IDAT"
= "="
initializer_list
{ "{"
char_literal
' "'"
character "I"
' "'"
, ","
char_literal
' "'"
character "D"
' "'"
, ","
char_literal
' "'"
character "A"
' "'"
, ","
char_literal
' "'"
character "T"
' "'"
} "}"
; ";"
declaration
qualified_identifier
namespace_identifier "std"
:: "::"
qualified_identifier
template_type
type_identifier "vector"
template_argument_list
< "<"
type_descriptor
type_identifier "uchar"
> ">"
:: "::"
type_identifier "iterator"
init_declarator
identifier "it"
= "="
call_expression
qualified_identifier
namespace_identifier "std"
:: "::"
identifier "search"
argument_list
( "("
call_expression
field_expression
identifier "buff"
. "."
field_identifier "begin"
argument_list
( "("
) ")"
, ","
call_expression
field_expression
identifier "buff"
. "."
field_identifier "end"
argument_list
( "("
) ")"
, ","
call_expression
field_expression
identifier "IDAT"
. "."
field_identifier "begin"
argument_list
( "("
) ")"
, ","
call_expression
field_expression
identifier "IDAT"
. "."
field_identifier "end"
argument_list
( "("
) ")"
) ")"
; ";"
expression_statement
binary_expression
call_expression
identifier "ASSERT_FALSE"
argument_list
( "("
binary_expression
identifier "it"
== "=="
call_expression
field_expression
identifier "buff"
. "."
field_identifier "end"
argument_list
( "("
) ")"
) ")"
<< "<<"
string_literal
" "\""
string_content "IDAT chunk not found"
" "\""
; ";"
comment "// Determine the range to test"
comment "// APNG stream contains as { len0, len1, len2, len3, 'I', 'D"...
declaration
primitive_type "size_t"
init_declarator
identifier "idx"
= "="
call_expression
qualified_identifier
namespace_identifier "std"
:: "::"
identifier "distance"
argument_list
( "("
call_expression
field_expression
identifier "buff"
. "."
field_identifier "begin"
argument_list
( "("
) ")"
, ","
identifier "it"
) ")"
; ";"
comment "// 'I' position"
declaration
primitive_type "size_t"
init_declarator
identifier "len"
= "="
binary_expression
binary_expression
binary_expression
parenthesized_expression
( "("
binary_expression
subscript_expression
identifier "buff"
subscript_argument_list
[ "["
binary_expression
identifier "idx"
- "-"
number_literal "4"
] "]"
<< "<<"
number_literal "24"
) ")"
+ "+"
parenthesized_expression
( "("
binary_expression
subscript_expression
identifier "buff"
subscript_argument_list
[ "["
binary_expression
identifier "idx"
- "-"
number_literal "3"
] "]"
<< "<<"
number_literal "16"
) ")"
+ "+"
parenthesized_expression
( "("
binary_expression
subscript_expression
identifier "buff"
subscript_argument_list
[ "["
binary_expression
identifier "idx"
- "-"
number_literal "2"
] "]"
<< "<<"
number_literal "8"
) ")"
+ "+"
parenthesized_expression
( "("
subscript_expression
identifier "buff"
subscript_argument_list
[ "["
binary_expression
identifier "idx"
- "-"
number_literal "1"
] "]"
) ")"
; ";"
comment "// IDAT chunk length"
expression_statement
assignment_expression
identifier "idx"
= "="
binary_expression
identifier "idx"
+ "+"
number_literal "4"
; ";"
comment "// Move to IDAT body"
comment "// Test"
for_statement
for "for"
( "("
declaration
primitive_type "size_t"
init_declarator
identifier "i"
= "="
number_literal "0"
; ";"
binary_expression
identifier "i"
< "<"
identifier "len"
; ";"
comma_expression
update_expression
identifier "i"
++ "++"
, ","
update_expression
identifier "idx"
++ "++"
) ")"
compound_statement
{ "{"
declaration
template_type
type_identifier "vector"
template_argument_list
< "<"
type_descriptor
primitive_type "uint8_t"
> ">"
init_declarator
identifier "work"
= "="
identifier "buff"
; ";"
expression_statement
assignment_expression
subscript_expression
identifier "work"
subscript_argument_list
[ "["
identifier "idx"
] "]"
= "="
call_expression
template_function
identifier "static_cast"
template_argument_list
< "<"
type_descriptor
primitive_type "uint8_t"
> ">"
argument_list
( "("
binary_expression
parenthesized_expression
( "("
binary_expression
call_expression
template_function
identifier "static_cast"
template_argument_list
< "<"
type_descriptor
primitive_type "uint32_t"
> ">"
argument_list
( "("
subscript_expression
identifier "work"
subscript_argument_list
[ "["
identifier "idx"
] "]"
) ")"
+ "+"
number_literal "1"
) ")"
& "&"
number_literal "0xff"
) ")"
; ";"
declaration
type_identifier "Mat"
identifier "dst"
; ";"
expression_statement
call_expression
identifier "EXPECT_NO_THROW"
argument_list
( "("
assignment_expression
identifier "dst"
= "="
call_expression
identifier "imdecode"
argument_list
( "("
identifier "work"
, ","
qualified_identifier
namespace_identifier "cv"
:: "::"
identifier "IMREAD_COLOR"
) ")"
) ")"
; ";"
if_statement
if "if"
condition_clause
( "("
call_expression
field_expression
identifier "dst"
. "."
field_identifier "empty"
argument_list
( "("
) ")"
) ")"
compound_statement
{ "{"
comment "// libpng detects some error, but the program is not crashed"...
break_statement
break "break"
; ";"
} "}"
} "}"
} "}"
#endif "#endif"
type_definition
typedef "typedef"
qualified_identifier
namespace_identifier "testing"
:: "::"
template_type
type_identifier "TestWithParam"
template_argument_list
< "<"
type_descriptor
type_identifier "string"
> ">"
type_identifier "Imgcodecs_Png_PngSuite"
; ";"
comment "// Parameterized test for decoding PNG files from the PNGSui"...
function_definition (+1143 nodes collapsed)
declaration (+769 nodes collapsed)
expression_statement (+21 nodes collapsed)
type_definition
typedef "typedef"
qualified_identifier
namespace_identifier "testing"
:: "::"
template_type
type_identifier "TestWithParam"
template_argument_list
< "<"
type_descriptor
type_identifier "string"
> ">"
type_identifier "Imgcodecs_Png_PngSuite_Gamma"
; ";"
comment "// Parameterized test for decoding PNG files from the PNGSui"...
function_definition (+202 nodes collapsed)
declaration (+63 nodes collapsed)
expression_statement (+21 nodes collapsed)
type_definition
typedef "typedef"
qualified_identifier
namespace_identifier "testing"
:: "::"
template_type
type_identifier "TestWithParam"
template_argument_list
< "<"
type_descriptor
type_identifier "string"
> ">"
type_identifier "Imgcodecs_Png_PngSuite_Corrupted"
; ";"
function_definition (+98 nodes collapsed)
declaration (+84 nodes collapsed)
expression_statement (+21 nodes collapsed)
expression_statement
call_expression
identifier "CV_ENUM"
argument_list
( "("
identifier "PNGStrategy"
, ","
identifier "IMWRITE_PNG_STRATEGY_DEFAULT"
, ","
identifier "IMWRITE_PNG_STRATEGY_FILTERED"
, ","
identifier "IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY"
, ","
identifier "IMWRITE_PNG_STRATEGY_RLE"
, ","
identifier "IMWRITE_PNG_STRATEGY_FIXED"
) ")"
; ";"
expression_statement (+22 nodes collapsed)
type_definition (+32 nodes collapsed)
function_definition (+266 nodes collapsed)
expression_statement (+227 nodes collapsed)
type_definition (+29 nodes collapsed)
function_definition (+199 nodes collapsed)
expression_statement (+159 nodes collapsed)
comment "// See https://github.com/opencv/opencv/issues/27614"
type_definition
typedef "typedef"
qualified_identifier
namespace_identifier "testing"
:: "::"
template_type
type_identifier "TestWithParam"
template_argument_list
< "<"
type_descriptor
primitive_type "int"
> ">"
type_identifier "Imgcodecs_Png_ZLIBBUFFER_SIZE"
; ";"
function_definition (+100 nodes collapsed)
expression_statement (+38 nodes collapsed)
#endif "#endif"
comment "// HAVE_PNG"
} "}"
} "}"
comment "// namespace"