Skip to content

Fix COMPRESS-709: GzipCompressorInputStream fails on trailing zero padding after the last member - #835

Open
Inf1mum wants to merge 1 commit into
apache:masterfrom
Inf1mum:fix/COMPRESS-709-gzip-zero-padding
Open

Inf1mum wants to merge 1 commit into
apache:masterfrom
Inf1mum:fix/COMPRESS-709-gzip-zero-padding

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 6, 2026

Copy link
Copy Markdown

Fixes COMPRESS-709.

Problem

A valid .gz stream followed by trailing zero bytes makes GzipCompressorInputStream in concatenated mode fail with "Unexpected data after a valid .gz stream." (reported as "Garbage after a valid .gz stream." in 1.26.x). GNU gzip decompresses the same input silently with exit code 0: trailing NUL padding after the last member is a common artifact of block-aligned storage and tape/file copies. The file attached to the ticket is a valid single-member gzip stream (CRC32 and ISIZE verified) whose 10,020 trailing zero bytes are pure padding - GNU gzip accepts it, commons-compress rejects it.

For reference, GNU gzip behavior:

  • trailing all-zero bytes after the last member: accepted silently, exit 0;
  • trailing non-zero garbage: "decompression OK, trailing garbage ignored", exit 2.

Change

When looking for the next member in concatenated mode (init(false)), if the byte after the member is 0x00, the remaining input is consumed: if it is all zeros, the stream ends cleanly; if any non-zero byte is found, the previous exception is thrown as before. Detection of the first member and non-concatenated mode are unchanged. The class Javadoc now documents the tolerated padding.

Tests

  • testCompress709TrailingZeroPaddingIsIgnored - a member followed by 16 KiB of zero padding decompresses cleanly in both concatenated and non-concatenated modes; it fails on unpatched master with exactly the reported exception.
  • testCompress709TrailingGarbageIsStillRejected - non-zero trailing garbage still throws "Unexpected data after a valid .gz stream.".

Verified end-to-end against the file attached to COMPRESS-709: decompresses to the same 204,288 bytes GNU gzip produces. In Docker maven:3.9-eclipse-temurin-21: mvn test over 37 compressor test classes - 273/273 green (1 pre-existing skip); mvn checkstyle:check passes.

…mber

Signed-off-by: Inf1mum <vadim.lazuk@mail.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant