Skip to content

Commit 46c4dfb

Browse files
committed
fixup! drop stale pickle references in comments after raw-bytes refactor
1 parent 378dc78 commit 46c4dfb

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

cuda_core/cuda/core/utils/_program_cache.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ def __init__(
11851185
existing = self._schema_path.read_text().strip()
11861186
if existing != expected:
11871187
# Schema mismatch: wipe incompatible entries. Losing cache
1188-
# contents is safe; returning stale/incompatible pickles is not.
1188+
# contents is safe; returning bytes from an old format is not.
11891189
for entry in list(self._iter_entry_paths()):
11901190
with contextlib.suppress(FileNotFoundError):
11911191
entry.unlink()
@@ -1201,9 +1201,10 @@ def _path_for_key(self, key: object) -> Path:
12011201
k = _as_key_bytes(key)
12021202
# Hash the key to a fixed-length identifier so arbitrary-length user
12031203
# keys never exceed per-component filename limits (typically 255 on
1204-
# ext4 / NTFS). The original key is still stored inside the pickled
1205-
# record and verified on read, so two distinct keys cannot collide
1206-
# silently (hash collision would surface as KeyError via key mismatch).
1204+
# ext4 / NTFS). With a 256-bit blake2b digest, the cache relies on
1205+
# cryptographic collision resistance for key uniqueness -- two
1206+
# distinct keys hashing to the same path is astronomically unlikely
1207+
# (~2^-128 with the 32-byte digest in use here).
12071208
digest = hashlib.blake2b(k, digest_size=32).hexdigest() if k else "empty"
12081209
if len(digest) < 3:
12091210
digest = digest.rjust(3, "0")

cuda_core/tests/test_program_cache.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ def test_filestream_cache_clear_does_not_break_concurrent_writer(tmp_path):
14711471

14721472
# Stage a temp file that mimics an in-flight write.
14731473
inflight_tmp = root / "tmp" / "entry-inflight"
1474-
inflight_tmp.write_bytes(b"\x80\x05fake-pickle") # contents do not matter
1474+
inflight_tmp.write_bytes(b"in-flight payload") # contents do not matter
14751475

14761476
# Concurrent clear() from another cache handle.
14771477
with FileStreamProgramCache(root) as other:
@@ -1502,8 +1502,8 @@ def test_filestream_cache_size_cap_does_not_unlink_replaced_file(tmp_path):
15021502

15031503
from cuda.core.utils import FileStreamProgramCache
15041504

1505-
# Cap fits two entries (each ~2123 bytes on disk for a 2000-byte
1506-
# payload, including pickle overhead) but not three.
1505+
# Cap fits two 2000-byte entries (raw payload only -- no per-entry
1506+
# framing) but not three.
15071507
cap = 5000
15081508
root = tmp_path / "fc"
15091509
with FileStreamProgramCache(root, max_size_bytes=cap) as cache:
@@ -1567,8 +1567,8 @@ def test_filestream_cache_size_cap_counts_tmp_files(tmp_path):
15671567

15681568
def test_filestream_cache_handles_long_keys(tmp_path):
15691569
"""Arbitrary-length keys must not overflow per-component filename limits.
1570-
The filename is a fixed-length hash; the original key is verified from
1571-
the pickled record."""
1570+
The filename is a fixed-length 256-bit blake2b digest; key uniqueness
1571+
relies on the digest's collision resistance."""
15721572
from cuda.core.utils import FileStreamProgramCache
15731573

15741574
long_bytes_key = b"x" * 4096

cuda_core/tests/test_program_cache_multiprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_concurrent_eviction_does_not_delete_replaced_file(tmp_path):
144144

145145
root = str(tmp_path / "fc")
146146
payload = b"X" * 2000
147-
cap = 5000 # fits ~2 entries of 2000B + pickle-free overhead
147+
cap = 5000 # fits 2 raw 2000B entries; the third write triggers eviction
148148

149149
ctx = _mp.get_context("spawn")
150150
done_event = ctx.Event()

0 commit comments

Comments
 (0)