@@ -54,6 +54,9 @@ iTXt chunk : http://www.vias.org/pngguide/chapter11_05.html
5454PNG tags : http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/PNG.html#TextualData
5555
5656*/
57+ namespace {
58+ constexpr int nullSeparators = 2 ;
59+ }
5760
5861// *****************************************************************************
5962// class member definitions
@@ -71,7 +74,7 @@ namespace Exiv2 {
7174 *outWidth = data.read_uint32 (0 , bigEndian);
7275 *outHeight = data.read_uint32 (4 , bigEndian);
7376
74- } // PngChunk::decodeIHDRChunk
77+ }
7578
7679 void PngChunk::decodeTXTChunk (Image* pImage,
7780 const DataBuf& data,
@@ -86,7 +89,7 @@ namespace Exiv2 {
8689#endif
8790 parseChunkContent (pImage, key.c_data (), key.size (), arr);
8891
89- } // PngChunk::decodeTXTChunk
92+ }
9093
9194 DataBuf PngChunk::decodeTXTChunk (const DataBuf& data,
9295 TxtChunkType type)
@@ -99,7 +102,7 @@ namespace Exiv2 {
99102#endif
100103 return parseTXTChunk (data, key.size (), type);
101104
102- } // PngChunk::decodeTXTChunk
105+ }
103106
104107 DataBuf PngChunk::keyTXTChunk (const DataBuf& data, bool stripHeader)
105108 {
@@ -129,7 +132,7 @@ namespace Exiv2 {
129132
130133 if (type == zTXt_Chunk)
131134 {
132- enforce (data.size () >= Safe::add (keysize, 2 ), Exiv2::kerCorruptedMetadata);
135+ enforce (data.size () >= Safe::add (keysize, nullSeparators ), Exiv2::kerCorruptedMetadata);
133136
134137 // Extract a deflate compressed Latin-1 text chunk
135138
@@ -145,8 +148,8 @@ namespace Exiv2 {
145148 }
146149
147150 // compressed string after the compression technique spec
148- const byte* compressedText = data.c_data (keysize + 2 );
149- long compressedTextSize = data.size () - keysize - 2 ;
151+ const byte* compressedText = data.c_data (keysize + nullSeparators );
152+ long compressedTextSize = data.size () - keysize - nullSeparators ;
150153 enforce (compressedTextSize < data.size (), kerCorruptedMetadata);
151154
152155 zlibUncompress (compressedText, compressedTextSize, arr);
@@ -165,8 +168,8 @@ namespace Exiv2 {
165168 else if (type == iTXt_Chunk)
166169 {
167170 enforce (data.size () >= Safe::add (keysize, 3 ), Exiv2::kerCorruptedMetadata);
168- const size_t nullSeparators = std::count (data.c_data (keysize+3 ), data.c_data (data.size ()), ' \0 ' );
169- enforce (nullSeparators >= 2 , Exiv2::kerCorruptedMetadata);
171+ const size_t nullCount = std::count (data.c_data (keysize+3 ), data.c_data (data.size ()), ' \0 ' );
172+ enforce (nullCount >= nullSeparators , Exiv2::kerCorruptedMetadata);
170173
171174 // Extract a deflate compressed or uncompressed UTF-8 text chunk
172175
@@ -235,8 +238,7 @@ namespace Exiv2 {
235238 }
236239
237240 return arr;
238-
239- } // PngChunk::parsePngChunk
241+ }
240242
241243 void PngChunk::parseChunkContent (Image* pImage, const byte* key, long keySize, const DataBuf& arr)
242244 {
0 commit comments