[BUG]: LocatedHeaderDir is mutable, so callers can poison the cached header-directory lookup
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
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ả
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
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 NVIDIA/cuda-python
-
bug cuda.core
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
NVIDIA/cuda-python#2886 · 1 bình luận ·
-
triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
NVIDIA/cuda-python#2717 ·
-
triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 90/100
NVIDIA/cuda-python#2712 ·
-
cuda.core triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
NVIDIA/cuda-python#2435 · 1 bình luận ·
-
CI/CD
NVIDIA/cuda-python#2926 · 1 người được giao ·
Tất cả issue của NVIDIA/cuda-python
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
babalae/bettergi-scripts-list#3674 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
caddyserver/caddy#8046 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zilliztech/memsearch#759 ·
-
[Bug]: classify_items.py cron script never includes its own required JSON schema in the prompt Đang mởcomp/cron P2 sweeper:risk-automation type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NousResearch/hermes-agent#117792 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
bancolombia/sentinel#20 ·