Skip to content

Commit

Permalink
Fix test failures on 32-bit platforms.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse authored and neheb committed Feb 26, 2023
1 parent a653043 commit 4a6d786
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
16 changes: 16 additions & 0 deletions tests/bash_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
from urllib import request
import system_tests

# Run `exiv2 --verbose --version` to find out if the Exiv2 binary is 32-bit or 64-bit.
def exiv2_is_64bit(bin_dir):
proc = subprocess.run(
[os.path.join(bin_dir, 'exiv2'), '--verbose', '--version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=bin_dir
)
proc.check_returncode()
m = re.search(r'^bits=([0-9]+)\s*$', proc.stdout.decode('utf-8'), re.MULTILINE)
numbits = int(m[1])
assert numbits in {32, 64}
return numbits == 64


"""
Part 1:
Expand Down Expand Up @@ -43,6 +57,8 @@ class Config:
if 'VALGRIND' in os.environ:
valgrind = os.environ['VALGRIND']

is_64bit = exiv2_is_64bit(bin_dir)

@classmethod
def init(cls):
""" Init test environments and variables that may be modified """
Expand Down
7 changes: 3 additions & 4 deletions tests/bugfixes/github/test_CVE_2017_14859.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import system_tests


class TestCvePoC(metaclass=system_tests.CaseMeta):

url = "https://github.com/Exiv2/exiv2/issues/74"

filename = "$data_path/005-invalid-mem"
commands = ["$exiv2 " + filename]
stdout = [""]
stderr = ["""$exiv2_exception_message """ + filename + """:
$kerFailedToReadImageData
"""]
stderr = ["""$exiv2_exception_message """ + filename + ":\n" +
("$kerFailedToReadImageData" if system_tests.BT.Config.is_64bit else "$kerCorruptedMetadata") +
"\n"]
retval = [1]

def compare_stderr(self, i, command, got_stderr, expected_stderr):
Expand Down
10 changes: 8 additions & 2 deletions tests/bugfixes/github/test_CVE_2017_14862.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ class TestCvePoC(metaclass=system_tests.CaseMeta):
filename = "$data_path/008-invalid-mem"
commands = ["$exiv2 -q " + filename]

stderr = [""]
retval = [0]
if system_tests.BT.Config.is_64bit:
stderr = [""]
retval = [0]
else:
stderr = ["""$exiv2_exception_message """ + filename + """:
$kerCorruptedMetadata
"""]
retval = [1]

compare_stdout = check_no_ASAN_UBSAN_errors

7 changes: 3 additions & 4 deletions tests/bugfixes/github/test_CVE_2017_14864.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import system_tests


class TestCvePoC(metaclass=system_tests.CaseMeta):

url = "https://github.com/Exiv2/exiv2/issues/73"

filename = "$data_path/02-Invalid-mem-def"
commands = ["$exiv2 -q " + filename]
stdout = [""]
stderr = ["""$exiv2_exception_message """ + filename + """:
$kerFailedToReadImageData
"""]
stderr = ["""$exiv2_exception_message """ + filename + ":\n" +
("$kerFailedToReadImageData" if system_tests.BT.Config.is_64bit else "$kerCorruptedMetadata") +
"\n"]
retval = [1]
6 changes: 3 additions & 3 deletions tests/bugfixes/github/test_CVE_2018_12265.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import system_tests


class AdditionOverflowInLoaderExifJpeg(metaclass=system_tests.CaseMeta):
"""
Regression test for bug #365:
Expand All @@ -17,6 +16,7 @@ class AdditionOverflowInLoaderExifJpeg(metaclass=system_tests.CaseMeta):
"""Error: Upper boundary of data for directory Image, entry 0x00fe is out of bounds: Offset = 0x0000002a, size = 64, exceeds buffer size by 22 Bytes; truncating the entry
Warning: Directory Image, entry 0x0201: Strip 0 is outside of the data area; ignored.
Warning: Directory Image, entry 0x0201: Strip 7 is outside of the data area; ignored.
"""
""" +
("" if system_tests.BT.Config.is_64bit else "Uncaught exception: Overflow in addition\n")
]
retval = [0]
retval = [0 if system_tests.BT.Config.is_64bit else 1]

0 comments on commit 4a6d786

Please sign in to comment.