-
-
Notifications
You must be signed in to change notification settings - Fork 35k
gh-148395: Add regression tests for decompressor UAF after MemoryError (CVE-2026-6100) #154713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1216,6 +1216,31 @@ def test_refleaks_in___init__(self): | |
| zlibd.__init__() | ||
| self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10) | ||
|
|
||
| @support.nomemtest | ||
| @unittest.skipUnless(hasattr(zlib, '_ZlibDecompressor'), | ||
| 'requires zlib._ZlibDecompressor') | ||
| def test_decompress_memoryerror_no_dangling_input(self): | ||
| # gh-148395 / CVE-2026-6100: after MemoryError in decompress(), the | ||
| # decompressor must not keep a dangling pointer into the input buffer. | ||
| import _testcapi | ||
| data = zlib.compress(b'x' * 4096) | ||
| for start in range(0, 40): | ||
| d = zlib._ZlibDecompressor() | ||
| try: | ||
| _testcapi.set_nomemory(start, start + 1) | ||
| try: | ||
| d.decompress(bytearray(data), max_length=0) | ||
| except MemoryError: | ||
| pass | ||
| finally: | ||
| _testcapi.remove_mem_hooks() | ||
| try: | ||
| out = d.decompress(bytearray(data)) | ||
| except (MemoryError, ValueError, EOFError, OSError, zlib.error): | ||
| continue | ||
|
Comment on lines
+1239
to
+1240
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the injected failure reaches the tail-buffer allocation ( Useful? React with 👍 / 👎. |
||
| self.assertIsInstance(out, bytes) | ||
| self.assertNotIn(b'\x00' * 64, out) | ||
|
|
||
|
|
||
| class CustomInt: | ||
| def __index__(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Add regression tests for the CVE-2026-6100 decompressor fix so a | ||
| ``bz2.BZ2Decompressor``, ``lzma.LZMADecompressor``, or | ||
| ``zlib._ZlibDecompressor`` that raised ``MemoryError`` during | ||
| ``decompress()`` cannot silently regain a dangling input pointer on | ||
| the next call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the injected failure reaches the tail-buffer allocation (
start == 2on a--with-pydebugbuild), removing bothbzs->next_in = NULLassignments from_bz2module.cmakes the follow-up call raiseOSError: Invalid data stream; this handler accepts that result, so the test still passes with the CVE fix reverted. Use a follow-up operation and explicit expected outcome that distinguish a cleared pointer from the dangling-pointer state rather than treating this decompression error as success.Useful? React with 👍 / 👎.