[BUG]: LocatedHeaderDir is mutable, so callers can poison the cached header-directory lookup
まだ誰も着手していません。
評価
調査の方向性
LocatedHeaderDir の定義と、locate_nvidia_header_directory() および find_nvidia_header_directory() のエントリポイントから始めます。実装を _static_libs/find_static_lib.py および _static_libs/find_bitcode_lib.py と比較し、その後 cuda.pathfinder のテストを実行します。検索動作を変更せずに、結果が不変かつ hashable になれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Cython
- スター
- 3.4k
- フォーク
- 329
- 平均マージ
- 1日 21時間
- マージ済み PR(30日)
- 113
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NVIDIA/cuda-python のほかの issue
-
bug cuda.core
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
NVIDIA/cuda-python#2886 · コメント 1 件 ·
-
triage
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
NVIDIA/cuda-python#2717 ·
-
triage
難易度 1/5 1〜3時間 初心者へのやさしさ 90/100
NVIDIA/cuda-python#2712 ·
-
cuda.core triage
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
NVIDIA/cuda-python#2435 · コメント 1 件 ·
-
CI/CD
NVIDIA/cuda-python#2926 · 担当者 1 名 ·
NVIDIA/cuda-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
hemilabs/ui-monorepo#2332 ·
-
Help-Wanted Needs-Triage Package-Update
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/winget-pkgs#438662 ·
-
priority: p3
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
googleapis/librarian#7636 ·
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
olcf/olcf-test-harness#278 · コメント 1 件 ·