Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect loop condition #1752

Merged
merged 2 commits into from
Jun 30, 2021
Merged
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/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,14 @@ static void boxes_check(size_t b,size_t m)
char* p = (char*) boxBuf.pData_;
bool bWroteColor = false ;

while ( count < length || !bWroteColor ) {
while ( count < length && !bWroteColor ) {
enforce(sizeof(Jp2BoxHeader) <= length - count, Exiv2::kerCorruptedMetadata);
Jp2BoxHeader* pSubBox = (Jp2BoxHeader*) (p+count) ;

// copy data. pointer could be into a memory mapped file which we will decode!
Jp2BoxHeader subBox = *pSubBox ;
// pSubBox isn't always an aligned pointer, so use memcpy to do the copy.
Jp2BoxHeader subBox;
memcpy(&subBox, pSubBox, sizeof(Jp2BoxHeader));
Jp2BoxHeader newBox = subBox;

if ( count < length ) {
Expand Down
Binary file added test/data/issue_ghsa_mxw9_qx4c_6m8v_poc.jp2
Binary file not shown.
11 changes: 5 additions & 6 deletions tests/bugfixes/github/test_issue_ghsa_8949_hhfh_j7rj.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path

from system_tests import CaseMeta, CopyTmpFiles, path
@CopyTmpFiles("$data_path/issue_ghsa_8949_hhfh_j7rj_poc.jp2","$data_path/issue_ghsa_8949_hhfh_j7rj_poc.exv")

class Jp2ImageEncodeJp2HeaderOutOfBoundsRead(metaclass=CaseMeta):
"""
Expand All @@ -10,13 +10,12 @@ class Jp2ImageEncodeJp2HeaderOutOfBoundsRead(metaclass=CaseMeta):
"""
url = "https://github.com/Exiv2/exiv2/security/advisories/GHSA-8949-hhfh-j7rj"

filename1 = path("$data_path/issue_ghsa_8949_hhfh_j7rj_poc.jp2")
filename2 = path("$data_path/issue_ghsa_8949_hhfh_j7rj_poc.exv")
filename1 = path("$tmp_path/issue_ghsa_8949_hhfh_j7rj_poc.jp2")
filename2 = path("$tmp_path/issue_ghsa_8949_hhfh_j7rj_poc.exv")
commands = ["$exiv2 in $filename1"]
stdout = [""]
stderr = [
"""Error: XMP Toolkit error 201: XML parsing failure
Warning: Failed to decode XMP metadata.
$filename1: Could not write metadata to file: $kerCorruptedMetadata
"""]
retval = [1]
retval = [0]
18 changes: 18 additions & 0 deletions tests/bugfixes/github/test_issue_ghsa_mxw9_qx4c_6m8v.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
@CopyTmpFiles("$data_path/issue_ghsa_mxw9_qx4c_6m8v_poc.jp2")

class Jp2ImageEncodeJp2HeaderOutOfBoundsRead2(metaclass=CaseMeta):
"""
Regression test for the bug described in:
https://github.com/Exiv2/exiv2/security/advisories/GHSA-mxw9-qx4c-6m8v
"""
url = "https://github.com/Exiv2/exiv2/security/advisories/GHSA-mxw9-qx4c-6m8v"

filename = path("$tmp_path/issue_ghsa_mxw9_qx4c_6m8v_poc.jp2")
commands = ["$exiv2 rm $filename"]
stdout = [""]
retval = [0]

compare_stderr = check_no_ASAN_UBSAN_errors