Skip to content

gh-156173: Fix zlib.Decompress.flush() silently returning corrupted output instead of raising zlib.error - #156176

Merged
StanFromIreland merged 1 commit into
python:mainfrom
StanFromIreland:zlib-flush-bug
Aug 23, 2026
Merged

gh-156173: Fix zlib.Decompress.flush() silently returning corrupted output instead of raising zlib.error#156176
StanFromIreland merged 1 commit into
python:mainfrom
StanFromIreland:zlib-flush-bug

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Aug 21, 2026

Copy link
Copy Markdown
Member

@StanFromIreland

Copy link
Copy Markdown
Member Author

I'm not sure about backporting, this is a behaviour change, although the old behaviour is incorrect.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

If the result is not truncated, but corrupted, error is reasonable.

What do other decompressors do? There is a large difference between zlib and others, so it may be not easy to draw a right parallel.

@StanFromIreland

Copy link
Copy Markdown
Member Author

They all error, testing zlib._ZlibDecompressor:

>>> import bz2, lzma, zlib; from compression import zstd
>>> payload = b'abcdefgh' * 200
>>> corrupt = lambda blob, keep: blob[:keep] + bytes(60)
>>> d = zlib.decompressobj()
>>> d.decompress(corrupt(zlib.compress(payload, 9), 15), 1)
b'a'
>>> d.flush()  # no error, but corrupt data.
b'bcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdeP'
>>> zlib._ZlibDecompressor().decompress(corrupt(zlib.compress(payload, 9), 15))
Traceback (most recent call last):
  File "<python-input-8>", line 1, in <module>
    zlib._ZlibDecompressor().decompress(corrupt(zlib.compress(payload, 9), 15))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
zlib.error: Error -3 while decompressing data: incorrect data check

@emmatyping

Copy link
Copy Markdown
Member

Backporting this is a good idea. If nothing else, this could alert users to silent data integrity failures.

@StanFromIreland StanFromIreland added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 23, 2026
@StanFromIreland
StanFromIreland merged commit 5442687 into python:main Aug 23, 2026
66 checks passed
@StanFromIreland
StanFromIreland deleted the zlib-flush-bug branch August 23, 2026 09:18
@miss-islington-app

Copy link
Copy Markdown

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

@bedevere-app

bedevere-app Bot commented Aug 23, 2026

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 23, 2026
@bedevere-app

bedevere-app Bot commented Aug 23, 2026

Copy link
Copy Markdown

GH-156271 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 Aug 23, 2026
@bedevere-app

bedevere-app Bot commented Aug 23, 2026

Copy link
Copy Markdown

GH-156272 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Aug 23, 2026
StanFromIreland added a commit that referenced this pull request Aug 23, 2026
…rrupted output instead of raising `zlib.error` (GH-156176) (#156272)

(cherry picked from commit 5442687)

Co-authored-by: Stan Ulbrych <stan@python.org>
StanFromIreland added a commit that referenced this pull request Aug 23, 2026
…rrupted output instead of raising `zlib.error` (GH-156176) (#156271)

(cherry picked from commit 5442687)

Co-authored-by: Stan Ulbrych <stan@python.org>
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.

3 participants