Skip to content

Commit 659db31

Browse files
Merge pull request Exiv2#3514 from kevinbackhouse/fix-issue-3513
Add enforce to check for integer overflow
2 parents eaa9e21 + 284b4e2 commit 659db31

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/psdimage.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ void PsdImage::readResourceBlock(uint16_t resourceId, uint32_t resourceSize) {
284284
nativePreview.height_ = getLong(buf + 8, bigEndian);
285285
const uint32_t format = getLong(buf + 0, bigEndian);
286286

287+
Internal::enforce(nativePreview.size_ <= static_cast<size_t>(std::numeric_limits<long>::max()),
288+
Exiv2::ErrorCode::kerCorruptedMetadata);
289+
287290
if (nativePreview.size_ > 0 && nativePreview.position_ > 0) {
288291
io_->seek(static_cast<long>(nativePreview.size_), BasicIo::cur);
289292
if (io_->error() || io_->eof())

test/data/issue_3513_poc.psd

206 Bytes
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import system_tests
4+
5+
6+
class test_issue_3513_PsdImage_readResourceBlock(metaclass=system_tests.CaseMeta):
7+
url = "https://github.com/Exiv2/exiv2/issues/3513"
8+
9+
filename = "$data_path/issue_3513_poc.psd"
10+
commands = ["$exiv2 -pp $filename"]
11+
retval = [1]
12+
stderr = [
13+
"""$exiv2_exception_message $filename:
14+
$kerCorruptedMetadata
15+
"""
16+
]
17+
stdout = [""]

tests/regression_tests/test_regression_allfiles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def get_valid_files(data_dir):
126126
"pocIssue283.jpg",
127127
"poc_1522.jp2",
128128
"xmpsdk.xmp",
129+
"issue_3513_poc.psd",
129130
"crash-23eba73bb01cb01caa96a389eb12955c34b98a37.jpg",
130131
"issue_3511_poc.eps",
131132
# large file that creates 11Mb of output so let's exclude it

0 commit comments

Comments
 (0)