code wiki / (root) / nx_fetchclean.nx

nx_fetchclean.nx

buildroot/runtime/nx_fetchclean.nx

8636 B194 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_fetchclean.nx -- REMOVE OUR OWN FETCH LANE'S DIAGNOSTIC PREAMBLE FROM A DOWNLOADED ASSET. WHY (measured 2026-08-07, caught by nx_assetprobe on its first real binary): nx_https_get prints transport diagnostics (nishi-tcc / nishi-cert / nishi-xfer) on the captured stream, AHEAD of the entity body. A genuine PNG fetched through our lane therefore read: bytes=13933 magic=UNKNOWN ext_claim=PNG verdict=UNIDENTIFIED because a 38-byte preamble displaced the magic from offset 0. Two real BVH files landed at exactly +38 bytes over their upstream size for the same reason; they survived only because BVH is text and gets a bounded scan. EVERY binary asset -- PMX, VMD, PNG, ZIP, GLB -- is broken by this, and each would have failed later, inside a loader, as an unexplained corruption. *THE FIX BELONGS IN THE PIPE, NOT IN THE RULER. Widening the magic check to "somewhere in the first N bytes" would have hidden this and destroyed the guarantee that makes a magic a magic. CLOSED PREFIX SET, LEADING RUN ONLY. We strip a line only if it begins with one of the four KNOWN diagnostic prefixes, and we stop at the first line that does not. A generic "starts with nishi-" rule would eat a legitimate body, and a whole-file rule would eat a payload that merely mentions the string. Never silent: the stripped byte and line counts are always printed. usage: nx_fetchclean <in> <out> nx_fetchclean --kat selftest: 5 teeth, 3 of them anti-vacuity exit 0 ok | 2 unreadable | 3 usage | 9 write-failed | 1 KAT RED license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_fetchclean.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main fc_puts sys_write fc_slen fc_slen ↻ fc_kat sys_mmap nxa_die sys_write ↻ sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ fc_put fc_slen ↻ fc_body_off fc_is_diag fc_at fc_slen ↻ fc_puts ↻ fc_num sys_mmap ↻ sys_write ↻ sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close fc_body_off ↻

structs

none

consts

26const FC_KATBUF: i64 = 4096
27const FC_MODE: i64 = 420
28const FC_NPFX: i64 = 4

functions

30func fc_slen(s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { i = i + 1 } return i }
31func fc_puts(s: *u8) -> i64 { sys_write(1, s, fc_slen(s)); return 0 }
called by 2: fc_katmain calls 2: sys_writefc_slen
32func fc_num(v: i64) -> i64
called by 2: fc_katmain calls 2: sys_mmapsys_write
47func fc_at(b: *u8, len: i64, off: i64, pat: *u8) -> i64
called by 1: fc_is_diag calls 1: fc_slen
56func fc_is_diag(b: *u8, len: i64, off: i64) -> i64
called by 1: fc_body_off calls 1: fc_at
65func fc_body_off(b: *u8, len: i64, lines: *i64) -> i64
called by 2: fc_katmain calls 1: fc_is_diag
89func fc_write(path: *u8, b: *u8, off: i64, len: i64) -> i64
99func fc_put(b: *u8, o: i64, s: *u8) -> i64
called by 1: fc_kat calls 1: fc_slen
106func fc_kat() -> i64
174func main(argc: i64, argv: *i64) -> i64