Skip to content
Repos

TOSV

Markdown 2.5 KB66 lines Opens in site

Directory Raw Download

64KB streaming

  • Status: SHIPPED, Gate 2 proves 100MB fetch at 5MB peak RSS
  • Spec: FR-04, FR-05, FR-06, NFR-03, NFR-04
  • Sources: tosv.cpp store path, archive/tosv.py stream_crypt, uploads/paste.txt vision, SPEC.md 6.2

What it is

Payload crypt walks the body in 64KB chunks with running offset math, so RAM stays flat no matter the blob size. The vision line is absolute: nothing the app does may ever sit wholly in memory, keys included. Store already streams; legacy fetch read whole blobs and FR-06 mandates the streaming fix.

How TOSV does it

The store handler slices the received body into 64KB pieces, calls crypt_buf per piece with the running offset, and appends to the blob file. The M2 fetch fix mirrors this: read blob file in 64KB, decrypt per piece, send per piece. Offset (off+i) mod 32 keeps every byte under a position-dependent keystream.

What it protects against

RAM-exhaustion denial of service (a 512MB drop costs 64KB of RAM), swap spills of whole files, and whole-file memory scrapes. It is a security property disguised as a performance trick.

Attack realism

High. Attackers routinely POST huge bodies at small vaults to OOM them; flat-RAM streaming plus the 512MB cap makes that attack cost the attacker bandwidth for zero effect. Multi-GB exfil scrapes of process RAM also collapse to 64KB windows.

Pros

Unbounded files in bounded RAM. Exact, testable property (Gate 2 fetches 100MB and asserts flat RSS). Shared primitive for both directions after M2.

Cons and how the vault resolves them

  • Legacy fetch violated it (whole-read). Resolved by FR-06 mandate in M2 with a Gate 2 flat-RAM check; the spec names the exact legacy sin so no model repeats it.
  • HTTP body arrives whole before chunking (Content-Length read). Resolved by the 512MB cap plus 64KB header cap: worst case is one capped body in RAM transiently, and true socket-to-disk streaming is tracked as v2 work.
  • Offset math must be exact across chunks. Resolved by one shared primitive plus round-trip tests (random bytes, random sizes including empty and exact-multiple, split points) in M4 plus M7.

Residual risk

Transient whole-body hold between socket read and chunk loop. Capped (512MB), kept in v2 for the AEAD pre-pass shape, true socket-to-disk streaming stays future work.

See also

32.8ms