Skip to content

gh-160314: Raise for a damaged later stream in lzma and bz2 - #160315

Merged
gpshead merged 2 commits into
python:mainfrom
gpshead:scanfix-lzma-3tvavl5a
Oct 31, 2026
Merged

gpshead merged 2 commits into
python:mainfrom
gpshead:scanfix-lzma-3tvavl5a

Conversation

@gpshead

@gpshead gpshead commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

DecompressReader.read(), lzma.decompress() and bz2.decompress() now ignore leftover data after a stream only when it does not start with the format's stream magic (the six .xz header bytes, or BZh1 to BZh9 as the bzip2 program requires); an error in data that does start with it is propagated. This is the same heuristic gzip uses to tell another member from trailing data. Trailing junk that happens to start with the magic bytes now raises instead of being ignored. A damaged later stream in the legacy .lzma container, which has no magic, is still dropped silently.

This touches the same decompress() loops in Lib/bz2.py and Lib/lzma.py as GH-160311, so the two conflict textually; whichever is merged second needs a rebase.

Fixes #160314

ANT-2026-3TVAVL5A

A damaged .xz or bzip2 stream that followed another stream was taken
for trailing data and silently ignored.  Leftover data that starts with
the stream magic is now treated as a stream, as gzip does.
@read-the-docs-community

read-the-docs-community Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35549385 | 📁 Comparing 317e551 against main (c3a1ad5)

  🔍 Preview build  

88 files changed · ± 88 modified

± Modified

@gpshead gpshead added the sprint label Oct 23, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Oct 23, 2026
@gpshead gpshead added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 31, 2026
Comment thread Lib/bz2.py Resolved
@gpshead
gpshead marked this pull request as ready for review October 31, 2026 19:39
@gpshead
gpshead enabled auto-merge (squash) October 31, 2026 19:40
@gpshead
gpshead merged commit a4f8047 into python:main Oct 31, 2026
55 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Sprint Oct 31, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @gpshead, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker a4f80477b02d53a592e6d3891686921c111ae771 3.15

@miss-islington-app

Copy link
Copy Markdown

Sorry, @gpshead, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker a4f80477b02d53a592e6d3891686921c111ae771 3.14

@bedevere-app

bedevere-app Bot commented Oct 31, 2026

Copy link
Copy Markdown

GH-161034 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 31, 2026
@bedevere-app

bedevere-app Bot commented Oct 31, 2026

Copy link
Copy Markdown

GH-161035 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 31, 2026
gpshead added a commit that referenced this pull request Oct 31, 2026
The bz2 and lzma docs gained versionchanged notes in GH-160315, but
bugfix-level behavior changes are not recorded with versionchanged.
gpshead added a commit that referenced this pull request Oct 31, 2026
…H-160315) (#161034)

A damaged .xz or bzip2 stream that followed another stream was taken
for trailing data and silently ignored.  Leftover data that starts with
the stream magic is now treated as a stream, as gzip does.

ANT-2026-3TVAVL5A

(cherry picked from commit a4f8047)
gpshead added a commit that referenced this pull request Oct 31, 2026
…H-160315) (#161035)

A damaged .xz or bzip2 stream that followed another stream was taken
for trailing data and silently ignored.  Leftover data that starts with
the stream magic is now treated as a stream, as gzip does.

ANT-2026-3TVAVL5A

(cherry picked from commit a4f8047)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

lzma and bz2 silently ignore a damaged later stream as trailing data

1 participant