python / python/cpython

Reading gzip file with very long filename or comment takes long time

Đang mở
#150,144 2 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

3.13 3.14 3.15 performance stdlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

The gzip file can contain filename and comment which are written like null terminated sequences of bytes. GzipFile ignores filename and comment (only calculates their checksum if needed), but simply searching for the terminating null byte, while reading byte-by-byte, takes time. On my computer, with fast CPU and SSD, reading a gzip file containing 1 GiB filename or comment will take over 5 minutes. This is not a security issue per se, because to trigger it, attacker need to send a large file at first place, but this is not fine.

This issue was discovered during discussion in #149945. The original proposed solution for that issue imposed a limit on the size of filename and comment. While the limit on filename is reasonable (but it can depend on platform?), we cannot be sure that there are no uses cases for large comments.

The following PR uses reading by chunks of growing size. It reads a 1 GiB header in fractions of second.

Linked PRs
  • gh-150145

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xem xét cách GzipFile xử lý các trường tên tệp và chú thích kết thúc bằng null, sau đó so sánh với phương pháp đọc theo từng khối được đề xuất trong PR #150145. Công việc được xem là hoàn tất khi việc đọc các header có trường rất dài không còn mất quá nhiều thời gian để quét từng byte một.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.