Skip to content

room-node: fix ckptdisk header validation, 64-bit pad4, and small-file modelFileId - #440

Open
Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/ckptdisk-validation-and-small-model-id
Open

Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/ckptdisk-validation-and-small-model-id

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 4, 2026

Copy link
Copy Markdown

Summary

Fixes four edge cases in packages/room-node/ckptdisk.js:

  1. Avoid 32-bit signed overflow in pad4(): (n + 3) & ~3 wraps negative once a part size or running file offset reaches 2 GiB (DEFAULT_CAP_GB = 4), causing off = pad4(off) in _put() to become negative and allowing forged/corrupt sizes pairs such as [2**31 + 4, 2**31 - 4] to sum to 0 in bodyBytes() and pass _header() on a 4096-byte file before crashing _get() with RangeError. Replaced with Math.ceil(n / 4) * 4 and additive off += pad.
  2. Validate header.pos and header.sizes elements in decodeHeader(): Reject negative pos and negative, non-integer, or string entries in sizes with CkptDiskError (and loop header reads via readExact() to avoid short reads on headers >64 KiB) so corrupt checkpoint files are treated as missing and removed cleanly.
  3. Clamp head read length in modelFileId() for small local files: localFileReader.readAt(0, 4 MiB) rejects reads past EOF on local GGUF files smaller than 4 MiB (such as synthetic test models), causing modelFileId() to return null. Clamping to Math.min(size, 4 MiB) hashes small local files cleanly while keeping the exact hash for files >= 4 MiB.
  4. Guard non-finite POOLED_CKPT_GB in CkptDisk.fromEnv(): Require Number.isFinite(gb) && gb > 0 so POOLED_CKPT_GB=Infinity falls back to DEFAULT_CAP_GB instead of disabling eviction.

Verification

  • Added 4 regression tests in packages/room-node/test/ckptdisk_test.mjs (all 4 confirmed failing prior to the fix, including reproducing the RangeError: Invalid typed array length: 2147483652 crash).
  • node --check packages/room-node/ckptdisk.js packages/room-node/test/ckptdisk_test.mjs — PASS.
  • node --test packages/room-node/test/ckptdisk_test.mjs — 17 pass, 0 fail.
  • npm run test:packages — 217 pass, 0 fail, 6 skipped.
  • npm run test:runtime — PASS (protocol: 4, 6/6 checks).

@Pybsama
Pybsama requested a review from Nehanth as a code owner December 4, 2026 08:44
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@Pybsama is attempting to deploy a commit to the nehanth's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant