Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "enforce.hpp"
#include "error.hpp"
#include "i18n.h" // NLS support.
#include "safe_op.hpp"

#include <ctime>
#include <iostream>
Expand Down Expand Up @@ -1011,10 +1012,11 @@ DataBuf packIfdId(const ExifData& exifData, IfdId ifdId, ByteOrder byteOrder) {
for (auto&& exif : exifData) {
if (exif.ifdId() != ifdId)
continue;
const uint16_t s = exif.tag() * 2 + static_cast<uint16_t>(exif.size());
const size_t s = Safe::add<size_t>(exif.tag() * 2, exif.size());
enforce(s <= static_cast<size_t>(std::numeric_limits<uint16_t>::max()), ErrorCode::kerCorruptedMetadata);
if (s <= size) {
if (len < s)
len = s;
len = static_cast<uint16_t>(s);
exif.copy(buf.data(exif.tag() * 2), byteOrder);
} else {
EXV_ERROR << "packIfdId out-of-bounds error: s = " << std::dec << s << "\n";
Expand Down
Binary file added test/data/issue_9324_poc.crw
Binary file not shown.
1 change: 1 addition & 0 deletions test/data/issue_9324_poc.txt

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions tests/bugfixes/github/test_issue_9324.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-

import system_tests


class test_issue_9324_packIfdId_overflow(metaclass=system_tests.CaseMeta):
url = "https://github.com/Exiv2/exiv2/issues/9324"

filename = "$data_path/issue_9324_poc.crw"
command_filename = "$data_path/issue_9324_poc.txt"
commands = ["$exiv2 -m $command_filename $filename"]
retval = [1]
stderr = [
"""Exiv2 exception in modify action for file $filename:
$kerCorruptedMetadata
"""
]
stdout = [""]
1 change: 1 addition & 0 deletions tests/regression_tests/test_regression_allfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def get_valid_files(data_dir):
"xmpsdk.xmp",
"issue_3513_poc.psd",
"issue_3511_poc.eps",
"issue_9324_poc.crw",
# large file that creates 11Mb of output so let's exclude it
"ReaganLargeTiff.tiff",
# files that don't create any output
Expand Down
Loading