Skip to content

Commit

Permalink
inflate: Include a test case with zero-length uncompressed block
Browse files Browse the repository at this point in the history
This is the exact DEFLATE stream reported by Peter Keunecke.
  • Loading branch information
keirf committed Feb 10, 2025
1 parent 6c79397 commit 9685c2a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion inflate/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ all: depacker degzip
# Test harness for inflate.S
test_inflate: degzip test_inflate.o
$(CC) -o $@ $@.o $(LDFLAGS)
$(PYTHON) test_inflate.py *.[cSo] *.asm ../cracking/protections/* ../cracking/cracks/nzs/gnu_c/* ../testkit/*
$(PYTHON) test_inflate.py *.[cSo] *.asm ../cracking/protections/* ../cracking/cracks/nzs/gnu_c/* ../testkit/* test_assets/*

%.o: %.S
$(CC) -o $@ -c $< $(AFLAGS)
Expand Down
Binary file added inflate/test_assets/XenonIcon.gz
Binary file not shown.
18 changes: 13 additions & 5 deletions inflate/test_inflate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Command for creating gzip files.
GZIP = "zopfli --i32 -c"
#GZIP = "gzip -c9"
GUNZIP = "gunzip -c"

HUNK_HEADER = 0x3f3
HUNK_CODE = 0x3e9
Expand All @@ -34,15 +35,22 @@ def main(argv):
def test(name):
print("Testing '%s'..." % name)

# _test_0: Local copy of original file
os.system('cp "' + name + '" ' + PREFIX + '0')
if name.endswith('.gz'):
# _test_1: Local copy of original gzipped file
os.system('cp "' + name + '" ' + PREFIX + '1')
# _test_0: Uncompressed file
os.system(GUNZIP + ' ' + PREFIX + '1 >' + PREFIX + '0')
else:
# _test_0: Local copy of original uncompressed file
os.system('cp "' + name + '" ' + PREFIX + '0')
# _test_1: Gzipped file
os.system(GZIP + ' ' + PREFIX + '0 >' + PREFIX + '1')

# CRC of uncompressed data
crc16 = crcmod.predefined.Crc('crc-ccitt-false')
with open(PREFIX + '0', 'rb') as f:
crc16.update(f.read())

# _test_1: Gzipped file
os.system(GZIP + ' ' + PREFIX + '0 >' + PREFIX + '1')

# _test_2: DEFLATE stream + custom header/footer
os.system('degzip -H ' + PREFIX + '1 ' + PREFIX + '2')

Expand Down

0 comments on commit 9685c2a

Please sign in to comment.