python / python/cpython

Guard against negative offset/length values in tarfile's GNU sparse extraction

Đang mở
#137,396 11 bình luận 0 reaction 2 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
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug report

Bug description:
for i in range(21):
    try:
        offset = nti(buf[pos:pos + 12])
        numbytes = nti(buf[pos + 12:pos + 24])
    except ValueError:
        break
    if offset and numbytes:
        structs.append((offset, numbytes))
    pos += 24

https://github.com/python/cpython/blob/7040aa54f14676938970e10c5f74ea93cd56aa38/Lib/tarfile.py#L1441

  • There is no check that offset or numbytes are non-negative.
  • The check if offset and numbytes: only skips zero, not negative numbers.
validation should be added:
if offset >= 0 and numbytes >= 0:
    structs.append((offset, numbytes))
  • This will prevent the addition of invalid sparse mappings, mitigating the risk.
CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs
  • gh-137805
  • gh-138726

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.

Đánh giá

Issue này chưa được đánh giá.

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.