Analyze minimum needed number of null separators in PngChunk::parseTXTChunk

This commit fixes the heap-buffer-overflow in PngChunk::parseTXTChunk.

According to the specification:
http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html

There must be 2 null separators when we start to analyze the language tag.
This commit is contained in:
Luis Diaz Mas
2018-05-19 19:39:30 +02:00
committed by Luis Díaz Más
parent 234e5794f6
commit 2fb00c8a16
2 changed files with 6 additions and 1 deletions
+5
View File
@@ -33,6 +33,7 @@
#include "iptc.hpp"
#include "image.hpp"
#include "error.hpp"
#include "enforce.hpp"
// + standard includes
#include <sstream>
@@ -42,6 +43,7 @@
#include <iostream>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <zlib.h> // To uncompress or compress text chunk
@@ -162,6 +164,9 @@ namespace Exiv2 {
}
else if(type == iTXt_Chunk)
{
const int nullSeparators = std::count(&data.pData_[keysize+3], &data.pData_[data.size_-1], '\0');
enforce(nullSeparators >= 2, Exiv2::kerCorruptedMetadata);
// Extract a deflate compressed or uncompressed UTF-8 text chunk
// we get the compression flag after the key
+1 -1
View File
@@ -13,5 +13,5 @@ class TestCvePoC(metaclass=system_tests.CaseMeta):
stdout = [""]
stderr = [
"""$exception_in_extract """ + filename + """:
$kerFailedToReadImageData
$kerCorruptedMetadata
"""]