`zlib._ZlibDecompressor(zdict=...)` raises `SystemError` on a zlib-wrapped stream
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Bắt đầu tại Modules/zlibmodule.c: đọc hàm khởi tạo của _ZlibDecompressor quanh các dòng 1775–1780 và decompress_buf quanh các dòng 1535–1541, sau đó so sánh cách Decompress xử lý Z_NEED_DICT quanh các dòng 932–938. Bổ sung kiểm thử cho trường hợp luồng có wrapper được ghi lại dưới tên ZlibDecompressorZdictTests.test_zlib_wrapper trong các bài kiểm thử Hypothesis của PR #159960; hoàn tất khi từ điển được cung cấp giải nén được luồng và trường hợp thiếu từ điển gây ra zlib.error.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug description
zlib._ZlibDecompressor accepts a zdict argument, but for a zlib-wrapped stream (positive wbits) compressed with that dictionary, decompress fails with a SystemError instead of decompressing. zlib.decompressobj handles the same input:
>>> import zlib
>>> zd = b"hello world " * 10
>>> c = zlib.compressobj(zdict=zd)
>>> s = c.compress(b"hello world hello") + c.flush()
>>> zlib.decompressobj(zdict=zd).decompress(s)
b'hello world hello'
>>> zlib._ZlibDecompressor(zdict=zd).decompress(s)
Traceback (most recent call last):
File "<python-input-5>", line 1, in <module>
zlib._ZlibDecompressor(zdict=zd).decompress(s)
SystemError: <method 'decompress' of 'zlib._ZlibDecompressor' objects> returned NULL without setting an exception
Raw deflate works, so this is specific to the wrapped format:
>>> c = zlib.compressobj(wbits=-15, zdict=zd)
>>> s = c.compress(b"hello world hello") + c.flush()
>>> zlib._ZlibDecompressor(-15, zdict=zd).decompress(s)
b'hello world hello'
Two things combine here. The constructor only applies the dictionary up front for raw deflate (wbits < 0): Modules/zlibmodule.c lines 1775-1780. For a wrapped stream zlib instead signals Z_NEED_DICT after reading the header, and decompress_buf handles that by jumping to error without setting an exception: Modules/zlibmodule.c lines 1535-1541. zlib.Decompress handles the same return by calling inflateSetDictionary and continuing: Modules/zlibmodule.c lines 932-938, which is presumably what _ZlibDecompressor should do as well (and raise zlib.error when no zdict was given, as Decompress does).
_ZlibDecompressor is private and gzip only uses it with wbits=-15, so the impact is low; but a SystemError from a C method is always a bug, and the argument is accepted for this case, so we may as well fix it.
Found by the Hypothesis tests in #159960, recorded there as ZlibDecompressorZdictTests.test_zlib_wrapper under expectedFailure.
CPython versions tested on
CPython main (4e3d5ecaad2), zlib 1.3.2
Operating systems tested on
Linux
- Ngôn ngữ chính
- Python
- Star
- 77.6k
- Fork
- 38.4k
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 589
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/cpython
-
type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
stdlib type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
stdlib topic-XML type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Docs: problem with page "msvcrt — Useful routines from the MS VC runtime"Có thể làm lại được @jikekei đã nhận 10 ngày trước và không có pull request nào đang mở. Đang mởdocs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
python/cpython#159072 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Document unpacking in generator expressions (PEP 798)Có thể đã có người làm @Marwan-verse đã nhận 8 ngày trước. Đang mởdocs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
python/cpython#159061 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python/cpython
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
anchore/grype-db#1149 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: `hermes plugins update` clones an entire monorepo twice - `subdir` is resolved but dropped at both catalog-update call sitesCó thể đã có người làm @HootRock đã nhận hôm nay. Đang mởcomp/cli P2 type/perf
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NousResearch/hermes-agent#142417 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SMC SPEC
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
tenstorrent/tt-oca-harness#3287 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug enhancement python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
DewaldOosthuizen/tech-cheat-sheets-and-notes#392 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Critical advisories on mainĐang mởsecurity
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
fabriziosalmi/wildbox#801 ·
Maintainer thường phản hồi trong vòng 1 ngày