[BUG]: LocatedHeaderDir is mutable, so callers can poison the cached header-directory lookup

Đang mở Phù hợp với người mới
#2,646 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

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
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu từ định nghĩa LocatedHeaderDir và các điểm vào locate_nvidia_header_directory() và find_nvidia_header_directory(). So sánh phần triển khai với _static_libs/find_static_lib.py và _static_libs/find_bitcode_lib.py, sau đó chạy các bài kiểm thử cuda.pathfinder. Hoàn thành khi kết quả là bất biến và hashable mà không thay đổi hành vi tra cứu.

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

Mô tả

triage
Component

cuda.pathfinder

What happened?

locate_nvidia_header_directory() is @functools.cache-backed and returns LocatedHeaderDir, which is a plain (mutable) dataclass. The cache hands every caller the same object, so a write to abs_path on a returned instance changes what every later lookup of that libname returns for the rest of the process, including through the find_nvidia_header_directory() wrapper.

LocatedHeaderDir is also the only one of the three public Located* return types that behaves this way: LocatedStaticLib (_static_libs/find_static_lib.py) and LocatedBitcodeLib (_static_libs/find_bitcode_lib.py) are both @dataclass(frozen=True). As a side effect of not being frozen, LocatedHeaderDir is also unhashable, so it cannot be put in a set or used as a dict key the way its two siblings can.

Reproduction
from cuda.pathfinder import locate_nvidia_header_directory, find_nvidia_header_directory

first = locate_nvidia_header_directory("cudart")
print(first.abs_path)                                # e.g. /usr/local/cuda/include

first.abs_path = "/somewhere/else"                   # caller "normalizes" the result in place

print(locate_nvidia_header_directory("cudart").abs_path)  # /somewhere/else
print(find_nvidia_header_directory("cudart"))             # /somewhere/else
>>> LocatedHeaderDir.__dataclass_params__.frozen, LocatedHeaderDir.__hash__ is not None
(False, False)
>>> LocatedStaticLib.__dataclass_params__.frozen, LocatedStaticLib.__hash__ is not None
(True, True)
>>> LocatedBitcodeLib.__dataclass_params__.frozen, LocatedBitcodeLib.__hash__ is not None
(True, True)
Suggested fix

Make LocatedHeaderDir @dataclass(frozen=True) so it matches the other two public Located* types. The __post_init__ path normalization then needs object.__setattr__. Nothing inside cuda_pathfinder or its tests mutates a LocatedHeaderDir, so this is contained to the public type's contract.

Ngôn ngữ chính
Cython
Star
3.4k
Fork
329
Merge trung bình
1 ngày 21 giờ
Pull request đã merge (30 ngày)
113

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.

Issue khác của NVIDIA/cuda-python

Tất cả issue của NVIDIA/cuda-python

Issue tương tự

Thêm issue về DevTools

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.