Skip to content

Commit 6fa2e31

Browse files
kevinbackhousepiponazo
authored andcommitted
Avoid negative integer overflow when iccOffset > chunkLength.
This fixes #790.
1 parent fe3f324 commit 6fa2e31

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/pngimage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "image_int.hpp"
3434
#include "basicio.hpp"
3535
#include "error.hpp"
36+
#include "enforce.hpp"
3637
#include "futils.hpp"
3738
#include "types.hpp"
3839

@@ -468,6 +469,7 @@ namespace Exiv2 {
468469
}
469470
profileName_ = std::string(reinterpret_cast<char *>(chunkData.pData_), iccOffset-1);
470471
++iccOffset; // +1 = 'compressed' flag
472+
enforce(iccOffset <= chunkLength, Exiv2::kerCorruptedMetadata);
471473

472474
zlibToDataBuf(chunkData.pData_ + iccOffset, chunkLength - iccOffset, iccProfile_);
473475
#ifdef DEBUG

test/data/issue_790_poc2.png

26 Bytes
Loading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import system_tests
2+
3+
4+
class IntegerOverflowInPngImageReadMetadata(
5+
metaclass=system_tests.CaseMeta):
6+
"""
7+
Regression test for the bug described in:
8+
https://github.com/Exiv2/exiv2/issues/790
9+
10+
Due to an integer overflow bug (#790), this test triggers an 8GB
11+
memory allocation. So the test will fail with a std::bad_alloc
12+
exception if less than 8GB is available. On Linux, you can use
13+
`ulimit -v 8000000` to reduce the available memory to slightly
14+
less than 8GB.
15+
"""
16+
url = "https://github.com/Exiv2/exiv2/issues/790"
17+
18+
filename = system_tests.path(
19+
"$data_path/issue_790_poc2.png"
20+
)
21+
commands = ["$exiv2 $filename"]
22+
stdout = [""]
23+
stderr = ["""Exiv2 exception in print action for file $filename:
24+
corrupted image metadata
25+
"""
26+
]
27+
retval = [1]

0 commit comments

Comments
 (0)