python / python/cpython

ZipFile.mkdir(ZipInfo.from_file(...)) CRC AttributeError

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

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

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

Mô tả

Bug report

Bug description:

Adding a directory entry to a zip file on the basis of a ZipInfo object (to pick up metadata) fails because ZipFile evidently expects the object to have a CRC attribute even though it's a directory rather than a file. I can work around this bug by storing the ZipInfo in a variable and giving it a nominal CRC (namely 0), but that shouldn't be necessary. Specifically,

import os
import zipfile
with zipfile.ZipFile("bug.zip", mode = "w") as z:
    os.chdir('/')
    z.mkdir(zipfile.ZipInfo.from_file('usr'))

fails:

  File ".../zipfile-bug.py", line 6, in <module>
    z.mkdir(zipfile.ZipInfo.from_file('usr'))
  File "/usr/lib/python3.12/zipfile/__init__.py", line 1935, in mkdir
    self.fp.write(zinfo.FileHeader(False))
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/zipfile/__init__.py", line 460, in FileHeader
    CRC = self.CRC
          ^^^^^^^^
AttributeError: 'ZipInfo' object has no attribute 'CRC'

Could you please take a look?

Thanks!

CPython versions tested on:

3.11, 3.12, 3.13

Operating systems tested on:

Linux

Linked PRs
  • gh-119108

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 với Lib/zipfile/init.py, đặc biệt là ZipFile.mkdir và ZipInfo.FileHeader, đồng thời tái hiện ví dụ ZipInfo.from_file('usr') được cung cấp. Kiểm tra các bài kiểm thử của zipfile đối với các mục thư mục và thêm coverage cho lời gọi này; được xem là hoàn tất khi ví dụ chạy xong mà không có AttributeError và các bài kiểm thử liên quan đều đạ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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả 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.