Skip to content

gh-159643: Fix EOFError in tarfile stream mode with bz2, xz and zstd - #159647

Open
digit50 wants to merge 1 commit into
python:mainfrom
digit50:fix/tarfile-stream-bz2-xz-zstd
Open

digit50 wants to merge 1 commit into
python:mainfrom
digit50:fix/tarfile-stream-bz2-xz-zstd

Conversation

@digit50

@digit50 digit50 commented Oct 17, 2026 •

Copy link
Copy Markdown

closes #159643

In stream mode (r|bz2, r|xz, r|zst, and r|* when it detects one of them), _Stream._read called decompress(b"") on a decompressor that had already reached the end of its data, because an exhausted BZ2Decompressor, LZMADecompressor or ZstdDecompressor reports needs_input as false. That raised a bare EOFError whenever tarfile read past the end of the compressed stream, for example with ignore_zeros=True or on an archive without end-of-archive blocks.

This change stops the read loop once the decompressor reports eof, which matches what the code did before the gh-121109 rewrite. The gzip branch is unchanged.

The new tests in StreamReadTest (run for plain, gzip, bz2, xz and zstd streams) read two concatenated archives with ignore_zeros=True and an archive that has no end-of-archive blocks, and check that the expected member names come back. Both fail with EOFError for bz2, xz and zstd without the fix.

… zstd

In stream mode the bz2, xz and zstd decompressors were fed again after reaching the end of their data, which raised a bare EOFError. Stop reading once the decompressor reports eof, as the code did before it was rewritten. Add stream-mode tests for concatenated archives with ignore_zeros and for an archive without end-of-archive blocks.
@digit50
digit50 requested a review from ethanfurman as a code owner October 17, 2026 19:37
@python-cla-bot

python-cla-bot Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tarfile stream mode raises EOFError reading past the end of bz2/xz/zstd data

1 participant