Skip to content

[3.14] gh-156002: Keep reading through monkey-patched zipfile decompressors (GH-157180) (GH-157268) - #157557

Merged
encukou merged 1 commit into
python:3.14from
miss-islington:backport-f507e69-3.14
Sep 16, 2026
Merged

encukou merged 1 commit into
python:3.14from
miss-islington:backport-f507e69-3.14

Conversation

@miss-islington

@miss-islington miss-islington commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin encukou@gmail.com
Co-authored-by: rasmusfaber rfaber@gmail.com

…ecompressors (pythonGH-157180) (pythonGH-157268)

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
@encukou
encukou merged commit 9d16799 into python:3.14 Sep 16, 2026
51 of 54 checks passed
@miss-islington
miss-islington deleted the backport-f507e69-3.14 branch September 16, 2026 13:52
encukou added a commit to miss-islington/cpython that referenced this pull request Sep 16, 2026
…ssors (pythonGH-157180) (pythonGH-157557)

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
encukou added a commit to miss-islington/cpython that referenced this pull request Sep 16, 2026
…ssors (pythonGH-157180) (pythonGH-157557)

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
encukou added a commit to miss-islington/cpython that referenced this pull request Sep 16, 2026
…ssors (pythonGH-157180) (pythonGH-157557)

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
encukou added a commit to miss-islington/cpython that referenced this pull request Sep 16, 2026
…ssors (pythonGH-157180) (pythonGH-157557)

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
Yhg1s pushed a commit that referenced this pull request Sep 29, 2026
…) (GH-156362) (#156738)

* [3.15] gh-156002: Bound zipfile decompression for bzip2/LZMA/Zstandard (GH-156003) (GH-156362)

Patch by @tonghuaroot.

zipfile.ZipExtFile._read1() bounds the output of each decompress() call
for DEFLATE members by passing a max_length to zlib, but for bzip2, LZMA,
and Zstandard members it called decompress() with no bound. A whole
compressed chunk was therefore expanded into a single allocation before
the data[:self._left] clip ran, so a consumer that deliberately reads in
small chunks to limit memory (for example zf.open(name).read(8192)) was
silently unprotected for non-DEFLATE members. A small, spec-conformant
archive member declaring a large uncompressed size could drive multi-GB
peak memory.

_read1() now passes a per-call bound to the non-DEFLATE decompress()
(mirroring the DEFLATE branch) and drains the decompressor's internal
buffer across calls by checking needs_input before reading more
compressed input. zipfile's LZMADecompressor wrapper forwards max_length
and exposes needs_input so the bound also holds for LZMA members.

(cherry picked from commit f897dbf)
(cherry picked from commit 1b424c0)

* gh-156002: Keep reading through monkey-patched zipfile decompressors (GH-157180) (GH-157557)
(cherry picked from commit f507e69)


Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
Yhg1s pushed a commit that referenced this pull request Sep 30, 2026
GH-156003) (GH-156362) (#156739)

* gh-156002: Bound zipfile decompression for bzip2/LZMA/Zstandard (GH-156003) (GH-156362)

Patch by @tonghuaroot.

zipfile.ZipExtFile._read1() bounds the output of each decompress() call
for DEFLATE members by passing a max_length to zlib, but for bzip2, LZMA,
and Zstandard members it called decompress() with no bound. A whole
compressed chunk was therefore expanded into a single allocation before
the data[:self._left] clip ran, so a consumer that deliberately reads in
small chunks to limit memory (for example zf.open(name).read(8192)) was
silently unprotected for non-DEFLATE members. A small, spec-conformant
archive member declaring a large uncompressed size could drive multi-GB
peak memory.

_read1() now passes a per-call bound to the non-DEFLATE decompress()
(mirroring the DEFLATE branch) and drains the decompressor's internal
buffer across calls by checking needs_input before reading more
compressed input. zipfile's LZMADecompressor wrapper forwards max_length
and exposes needs_input so the bound also holds for LZMA members.

(cherry picked from commit f897dbf)
(cherry picked from commit 1b424c0)

* gh-156002: Keep reading through monkey-patched zipfile decompressors (GH-157180) (GH-157557)

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
pablogsal pushed a commit that referenced this pull request Oct 1, 2026
GH-156003) (GH-156362) (#156741)

* [3.15] gh-156002: Bound zipfile decompression for bzip2/LZMA/Zstandard (GH-156003) (GH-156362)

Patch by @tonghuaroot.

zipfile.ZipExtFile._read1() bounds the output of each decompress() call
for DEFLATE members by passing a max_length to zlib, but for bzip2, LZMA,
and Zstandard members it called decompress() with no bound. A whole
compressed chunk was therefore expanded into a single allocation before
the data[:self._left] clip ran, so a consumer that deliberately reads in
small chunks to limit memory (for example zf.open(name).read(8192)) was
silently unprotected for non-DEFLATE members. A small, spec-conformant
archive member declaring a large uncompressed size could drive multi-GB
peak memory.

_read1() now passes a per-call bound to the non-DEFLATE decompress()
(mirroring the DEFLATE branch) and drains the decompressor's internal
buffer across calls by checking needs_input before reading more
compressed input. zipfile's LZMADecompressor wrapper forwards max_length
and exposes needs_input so the bound also holds for LZMA members.

(cherry picked from commit f897dbf)
(cherry picked from commit 1b424c0)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>

* Remove zstd test (3.14+)

* gh-156002: Keep reading through monkey-patched zipfile decompressors (GH-157180) (GH-157557)

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>

* Avoid unittest's enterContext; it doesn't exist yet

* Don't use the :cve: RST role, it doesn't exist yet

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
pablogsal pushed a commit that referenced this pull request Oct 1, 2026
GH-156003) (GH-156362) (#156740)

* [3.15] gh-156002: Bound zipfile decompression for bzip2/LZMA/Zstandard (GH-156003) (GH-156362)

Patch by @tonghuaroot.

zipfile.ZipExtFile._read1() bounds the output of each decompress() call
for DEFLATE members by passing a max_length to zlib, but for bzip2, LZMA,
and Zstandard members it called decompress() with no bound. A whole
compressed chunk was therefore expanded into a single allocation before
the data[:self._left] clip ran, so a consumer that deliberately reads in
small chunks to limit memory (for example zf.open(name).read(8192)) was
silently unprotected for non-DEFLATE members. A small, spec-conformant
archive member declaring a large uncompressed size could drive multi-GB
peak memory.

_read1() now passes a per-call bound to the non-DEFLATE decompress()
(mirroring the DEFLATE branch) and drains the decompressor's internal
buffer across calls by checking needs_input before reading more
compressed input. zipfile's LZMADecompressor wrapper forwards max_length
and exposes needs_input so the bound also holds for LZMA members.

(cherry picked from commit f897dbf)
(cherry picked from commit 1b424c0)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>

* Remove zstd test (3.14+)

* gh-156002: Keep reading through monkey-patched zipfile decompressors (GH-157180) (GH-157557)

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>

* Don't use the :cve: RST role, it doesn't exist yet

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
icanhasmath pushed a commit to ActiveState/cpython that referenced this pull request Oct 28, 2026
…tandard (pythonGH-156003) (pythonGH-156362) (python#156741)

* [3.15] pythongh-156002: Bound zipfile decompression for bzip2/LZMA/Zstandard (pythonGH-156003) (pythonGH-156362)

Patch by @tonghuaroot.

zipfile.ZipExtFile._read1() bounds the output of each decompress() call
for DEFLATE members by passing a max_length to zlib, but for bzip2, LZMA,
and Zstandard members it called decompress() with no bound. A whole
compressed chunk was therefore expanded into a single allocation before
the data[:self._left] clip ran, so a consumer that deliberately reads in
small chunks to limit memory (for example zf.open(name).read(8192)) was
silently unprotected for non-DEFLATE members. A small, spec-conformant
archive member declaring a large uncompressed size could drive multi-GB
peak memory.

_read1() now passes a per-call bound to the non-DEFLATE decompress()
(mirroring the DEFLATE branch) and drains the decompressor's internal
buffer across calls by checking needs_input before reading more
compressed input. zipfile's LZMADecompressor wrapper forwards max_length
and exposes needs_input so the bound also holds for LZMA members.

(cherry picked from commit f897dbf)
(cherry picked from commit 1b424c0)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>

* Remove zstd test (3.14+)

* pythongh-156002: Keep reading through monkey-patched zipfile decompressors (pythonGH-157180) (pythonGH-157557)

(cherry picked from commit f507e69)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>

* Avoid unittest's enterContext; it doesn't exist yet

* Don't use the :cve: RST role, it doesn't exist yet

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
(cherry picked from commit c2bfbcd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants