Skip to content

Commit 39143cb

Browse files
committed
fix(cactus): apply spec.size pre-check on browser Cache Storage hit path
The browser network path already byte-length-checks `spec.size` before calling `verifySha256`. The Cache Storage hit path skipped it. Adding the pre-check inside the existing try-block lets the existing catch branch (which deletes the cache entry and falls through to refetch) handle size and hash mismatches uniformly.
1 parent 97e4710 commit 39143cb

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎providers/cactus/src/ai/common/Cactus_Runtime.browser.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ async function fetchAssetBytesBrowser(
135135
if (hit) {
136136
const bytes = new Uint8Array(await hit.arrayBuffer());
137137
try {
138+
// Cheap pre-check: a wrong-size cached entry cannot match the catalog.
139+
// Throwing CactusIntegrityError here flows through the same catch
140+
// branch that deletes the cache entry and falls through to refetch —
141+
// so size and hash mismatches are handled uniformly.
142+
if (spec.size > 0 && bytes.byteLength !== spec.size) {
143+
throw new CactusIntegrityError({
144+
url,
145+
filename: spec.filename,
146+
expected: `${spec.size} bytes`,
147+
actual: `${bytes.byteLength} bytes`,
148+
});
149+
}
138150
await verifySha256(bytes, spec.sha256, { url, filename: spec.filename });
139151
return bytes;
140152
} catch (err) {

0 commit comments

Comments
 (0)