code wiki / _hdl_build / nx_lora_screen_lib.nx
nx_lora_screen_lib.nx
buildroot/runtime/_hdl_build/nx_lora_screen_lib.nx
about
nx_lora_screen_lib.nx -- LIB: the G16 lc_screen judgement (static contamination/integrity screen on an acquired
LoRA or checkpoint FILE, before it may enter elara_loras.txt or the served model path). The lib carries ALL the
judgement so nx_lora_screen_gate proves it in-process against crafted fixtures (the lib+program split that makes
a gate honest); runtime/nx_lora_screen.nx is the thin main.
WHAT IT JUDGES (.safetensors): the 8-byte LE header length, the JSON header's declared data_offsets, and whether
those extents exactly tile the file's data region. A file whose declared sizes disagree with its bytes is either
truncated, forged, or carrying an undeclared payload -- each flag is NAMED with its values printed.
DECLARED IMPRECISION (so the next reader does not trust this as exact): the tiling check compares sum(extents)
and max(end) to the region -- a gap and an overlap of EQUAL size cancel and pass; full interval-overlap proof
is deliberately not implemented (sort-free single pass). Every real-world serializer writes tensors back to
back, which sum==max_end==region does prove.
.ckpt/.pt/.pth/.bin/.pkl are REFUSED OUTRIGHT: pickled checkpoints execute arbitrary code on load (CWE-502);
the remedy is to obtain a .safetensors export. This is a refusal, not a flag -- there is no safe way to screen
a pickle by reading it.
verdicts (returned by lc_screen, printed with values): 0 CLEAN | 1 FLAGGED | 3 UNPROVEN (unreadable or a format
this screen cannot judge -- abstain, never acquit) | 4 REFUSED-pickle
license_tier: ORIGINAL
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_lora_screen.nxnx_lora_screen_gate.nx
structs
| none |
consts
| 21 | const LC_HDR_CAP: i64 = 16777216 // 16 MiB header ceiling: real safetensors headers are far below this; a bigger one is FLAGGED, never silently truncated |
| 22 | const LC_META_EXCERPT: i64 = 700 // bytes of __metadata__ printed (trigger words live here) |
functions
| 24 | func lc_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 25 | func lc_lc(c: i64) -> i64 { if c>=65 { if c<=90 { return c+32 } } return c } called by 1: lc_ends_ci |
| 26 | func lc_put(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 27 | func lc_num(v: i64) -> i64 |
| 42 | func lc_ends_ci(path: *u8, ext: *u8) -> i64 |
| 55 | func lc_class(path: *u8) -> i64 |
| 66 | func lc_u64le(b: *u8) -> i64 called by 1: lc_screen |
| 73 | func lc_find(buf: *u8, n: i64, from: i64, needle: *u8) -> i64 |
| 87 | func lc_parse_uint(buf: *u8, n: i64, pos: i64) -> i64 called by 1: lc_scan_offsets |
| 103 | func lc_scan_offsets(json: *u8, n: i64, res: *i64) -> i64 |
| 139 | func lc_metadata_print(json: *u8, n: i64) -> i64 |
| 167 | func lc_screen(path: *u8) -> i64 |