code wiki / _hdl_build / nx_lora_screen_lib.nx

nx_lora_screen_lib.nx

buildroot/runtime/_hdl_build/nx_lora_screen_lib.nx

10609 B250 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind librarytopic lora
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_lora_screen_lib.nx nx_lora_screen.nx nx_lora_screen_gate.nx

imports: nx_syscalls.nx

imported by: nx_lora_screen.nxnx_lora_screen_gate.nx

structs

none

consts

21const LC_HDR_CAP: i64 = 16777216 // 16 MiB header ceiling: real safetensors headers are far below this; a bigger one is FLAGGED, never silently truncated
22const LC_META_EXCERPT: i64 = 700 // bytes of __metadata__ printed (trigger words live here)

functions

24func lc_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
25func lc_lc(c: i64) -> i64 { if c>=65 { if c<=90 { return c+32 } } return c }
called by 1: lc_ends_ci
26func 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 }
27func lc_num(v: i64) -> i64
called by 1: lc_screen calls 3: lc_putsys_mmapsys_write
42func lc_ends_ci(path: *u8, ext: *u8) -> i64
called by 1: lc_class calls 2: lc_slenlc_lc
55func lc_class(path: *u8) -> i64
called by 2: mainlc_screen calls 1: lc_ends_ci
66func lc_u64le(b: *u8) -> i64
called by 1: lc_screen
73func lc_find(buf: *u8, n: i64, from: i64, needle: *u8) -> i64
87func lc_parse_uint(buf: *u8, n: i64, pos: i64) -> i64
called by 1: lc_scan_offsets
103func lc_scan_offsets(json: *u8, n: i64, res: *i64) -> i64
139func lc_metadata_print(json: *u8, n: i64) -> i64
167func lc_screen(path: *u8) -> i64