Skip to content

feat: binary format v2 — CRC32, header padding, strict reader, zero-copy ready - #62

Merged
krish1925 merged 1 commit into
developmentfrom
feat/binary-format-v2
Jul 28, 2026
Merged

krish1925 merged 1 commit into
developmentfrom
feat/binary-format-v2

Conversation

@krish1925

Copy link
Copy Markdown
Owner

Summary

Upgrades binary format from v1 to v2 with critical safety and performance fixes. Both npm () and Python () packages updated.

Binary format v2 changes

  • 8-byte header padding: JSON header padded to 8-byte boundary, enabling zero-copy views on the read path (was previously impossible — every load copied 37MB+ on cold start)
  • CRC32 checksum: CRC32 over entire file (excluding checksum field) for corruption detection at load time
  • Strict reader: unknown header keys throw, missing required keys throw (previously silently produced empty matrices — the worst failure mode for a numerical library)
  • Header length cap: validated against 1MB ceiling before allocation (DoS mitigation for attacker-controlled LE uint32)
  • Payload size assertion: must equal remaining bytes exactly (catches truncation at format layer rather than via test)
  • Endianness assertion: module-init check that platform is LE (documented as format requirement)
  • Prototype pollution fix: uses to prevent injection from adversarial JSON

Also included

  • SVD one-sided Jacobi with m<n transpose fix (was broken for wide matrices)
  • Cross-compat test suite (22 tests) with Python fixture parity
  • Correctness test suite (127 tests) with Python-generated fixtures
  • 268 total tests passing across 8 suites
  • Python writer updated to v2 format with matching CRC32
  • CHANGELOGs updated in both packages

Backward compatibility

  • v1 files (no CRC, no padding) are still loadable
  • v2 files written by TS can be read by Python and vice versa
  • bumped from 1 → 2

Test plan

  • 268/268 tests pass (8 suites)
  • TypeScript compiles clean (tsc --noEmit)
  • Python CRC32 matches TS CRC32 for identical data
  • Cross-runtime fixture parity verified

…opy ready

Binary format changes (format v2):
- Pad JSON header to 8-byte boundary for zero-copy Float64Array views
- Add CRC32 checksum over entire file (excluding checksum field)
- Cap headerLen at 1MB before allocation (DoS mitigation)
- Assert payload size = rows × cols × 8 exactly (catches truncation)
- Strict reader: unknown keys throw, missing required keys throw
- normalizeHeaderKeys uses Object.create(null) (prototype pollution fix)
- Module-init endianness assertion (LE required)
- Backward compatible: v1 files still loadable

Also includes:
- SVD one-sided Jacobi with m<n transpose fix
- Cross-compat test suite (22 tests) with Python fixture parity
- Correctness test suite (127 tests) with Python-generated fixtures
- 268 total tests passing across 8 suites
- Python writer updated to v2 format
- CHANGELOGs updated in both npm and Python packages
@krish1925
krish1925 merged commit 93cb809 into development Jul 28, 2026
2 of 6 checks passed
@krish1925
krish1925 deleted the feat/binary-format-v2 branch July 28, 2026 09:36
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