keyTXTChunk improvement

This commit is contained in:
Luis Díaz Más 2022-01-06 16:55:14 +01:00
parent c19425f6a4
commit 061df50cea
2 changed files with 10 additions and 12 deletions

View File

@ -107,20 +107,18 @@ namespace Exiv2 {
const int offset = stripHeader ? 8 : 0;
if (data.size() <= offset)
throw Error(kerFailedToReadImageData);
const byte *key = data.c_data(offset);
// Find null chatecter at end of keyword.
int keysize=0;
while (key[keysize] != 0)
{
keysize++;
// look if keysize is valid.
if (keysize+offset >= data.size())
throw Error(kerFailedToReadImageData);
/// \todo move conditional out of the loop
// Search for null char until the end of the DataBuf
const byte* dataPtr = data.c_data();
int keysize=offset;
while (dataPtr[keysize] != 0 && keysize < data.size()) {
keysize++;
}
return DataBuf(key, keysize);
if (keysize == data.size())
throw Error(kerFailedToReadImageData);
return DataBuf(dataPtr+offset, keysize-offset);
}
DataBuf PngChunk::parseTXTChunk(const DataBuf& data,

View File

@ -39,7 +39,7 @@ TEST(PngChunk, keyTxtChunkExtractsKeywordCorrectlyInPresenceOfNullChar)
DataBuf key = Internal::PngChunk::keyTXTChunk(chunkBuf, true);
ASSERT_EQ(21, key.size());
ASSERT_TRUE(std::equal(key.data(), key.data()+key.size(), data.data()+8, data.data()+8+key.size()));
ASSERT_TRUE(std::equal(key.data(), key.data()+key.size(), data.data()+8));
}