Skip to content

Commit

Permalink
Prevent SIGABRT on excessive subBox length in jp2image.cpp
Browse files Browse the repository at this point in the history
This fixes CVE-2018-9145
  • Loading branch information
rcsanchez97 authored and piponazo committed Oct 10, 2018
1 parent af44cec commit c03f732
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ namespace Exiv2
subBox.length = getLong((byte*)&subBox.length, bigEndian);
subBox.type = getLong((byte*)&subBox.type, bigEndian);

// subBox.length makes no sense if it is larger than the rest of the file
if (subBox.length > io_->size() - io_->tell()) {
throw Error(kerCorruptedMetadata);
}
DataBuf data(subBox.length-sizeof(box));
io_->read(data.pData_,data.size_);
if ( bPrint ) {
Expand Down
Binary file added test/data/4-DataBuf-abort-1
Binary file not shown.
26 changes: 26 additions & 0 deletions tests/bugfixes/github/test_CVE_2018_9145.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

import system_tests


class SubBoxLengthDataBufAbort(metaclass=system_tests.CaseMeta):

url = "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-9145"

filename = system_tests.path(
"$data_path/4-DataBuf-abort-1"
)
commands = ["$exiv2 -pR $filename"]
stdout = [
"""STRUCTURE OF JPEG2000 FILE: $filename
address | length | box | data
0 | 12 | jP |
12 | 20 | jp2h |
"""
]
stderr = [
"""$exiv2_exception_message $filename:
$kerCorruptedMetadata
"""
]
retval = [1]

0 comments on commit c03f732

Please sign in to comment.