code wiki / (root) / nx_uxf_ebml_gate.nx

nx_uxf_ebml_gate.nx source

↩ module page · 73 lines · 4324 B

1// nx_uxf_ebml_gate.nx -- the D001 MIGRATION of nx_uxf_ebml_test onto nx_gate_verdict (2026-09-06). 2// 3// IT DRIVES THE EXTRACTED LIB, NOT A SECOND COPY. nx_uxf_ebml_test carried its own ebml_vint_len, 4// ebml_read_id and ebml_read_size, byte-for-byte the same logic that now lives in nx_uxf_remux.nx as 5// uxr_vint_len, uxr_read_id and uxr_read_size. Migrating the test's teeth onto the LIB means the estate 6// keeps exactly one EBML reader instead of a test copy and a shipping copy that can drift apart -- which is 7// the duplicate-ruler defect this family already paid for once. 8// 9// ALL FIVE ORIGINAL TEETH PRESERVED IN PREDICATE, with T2 and T3 split so the VALUE and the CURSOR ADVANCE 10// are separately falsifiable: the original asserted both inside one conjunction, so a reader that returned 11// the right number without advancing would have failed without saying which half broke. 12// license_tier: ORIGINAL No hw writes (Rule 26). 13import "nx_gate_verdict.nx" 14import "nx_syscalls.nx" 15import "nx_uxf_remux.nx" 16 17const UE_BUF: i64 = 64 18const UE_EBML_MAGIC: i64 = 440786851 // 0x1A45DFA3, the real EBML document header id 19const UE_MAGIC_VINT_LEN: i64 = 4 20const UE_SIZE_VALUE: i64 = 4 21const UE_POS_AFTER_ID: i64 = 4 22const UE_POS_AFTER_SIZE: i64 = 5 23 24func main(argc: i64, argv: *i64) -> i64 { 25 let ctr: *i64 = gv_ctr() 26 gv_head("nx_uxf_remux EBML primitives -- the INPUT side of an MKV to MP4 rewrap" as *u8) 27 28 // EBML magic id 0x1A45DFA3, then a size vint 0x84 meaning 4, then 4 data bytes 29 let buf: *u8 = sys_mmap(UE_BUF) 30 buf[0] = 0x1A as u8; buf[1] = 0x45 as u8; buf[2] = 0xDF as u8; buf[3] = 0xA3 as u8 31 buf[4] = 0x84 as u8 32 buf[5] = 0xDE as u8; buf[6] = 0xAD as u8; buf[7] = 0xBE as u8; buf[8] = 0xEF as u8 33 34 let pos: *i64 = sys_mmap(8) as *i64 35 pos[0] = 0 36 let id: i64 = uxr_read_id(buf, pos) 37 let pos_after_id: i64 = pos[0] 38 let sz: i64 = uxr_read_size(buf, pos) 39 let pos_after_size: i64 = pos[0] 40 41 gv_check_eq("T1 the vint length of 0x1A is 4, so the EBML magic is a four-byte vint" as *u8, uxr_vint_len(0x1A), UE_MAGIC_VINT_LEN, ctr) 42 gv_check_eq("T2a the element id reads as the real EBML magic with its marker bit KEPT" as *u8, id, UE_EBML_MAGIC, ctr) 43 gv_check_eq("T2b reading the id advanced the cursor by exactly the vint length" as *u8, pos_after_id, UE_POS_AFTER_ID, ctr) 44 gv_check_eq("T3a the size vint reads as 4 with its marker bit STRIPPED" as *u8, sz, UE_SIZE_VALUE, ctr) 45 gv_check_eq("T3b reading the size advanced the cursor by exactly one byte" as *u8, pos_after_size, UE_POS_AFTER_SIZE, ctr) 46 47 // T4: every vint length class 1 through 8, each asserted separately so a failure names its class 48 gv_check_eq("T4a vint length class 1 for 0x80" as *u8, uxr_vint_len(0x80), 1, ctr) 49 gv_check_eq("T4b vint length class 2 for 0x40" as *u8, uxr_vint_len(0x40), 2, ctr) 50 gv_check_eq("T4c vint length class 3 for 0x20" as *u8, uxr_vint_len(0x20), 3, ctr) 51 gv_check_eq("T4d vint length class 4 for 0x10" as *u8, uxr_vint_len(0x10), 4, ctr) 52 gv_check_eq("T4e vint length class 5 for 0x08" as *u8, uxr_vint_len(0x08), 5, ctr) 53 gv_check_eq("T4f vint length class 6 for 0x04" as *u8, uxr_vint_len(0x04), 6, ctr) 54 gv_check_eq("T4g vint length class 7 for 0x02" as *u8, uxr_vint_len(0x02), 7, ctr) 55 gv_check_eq("T4h vint length class 8 for 0x01" as *u8, uxr_vint_len(0x01), 8, ctr) 56 57 gv_check_eq("neg-control-a-malformed-vint-with-no-marker-bit-reads-length-ZERO-and-is-not-silently-accepted" as *u8, uxr_vint_len(0x00), 0, ctr) 58 59 gv_values_head() 60 gv_kv("read_id" as *u8, id) 61 gv_kv("expected_ebml_magic" as *u8, UE_EBML_MAGIC) 62 gv_kv("pos_after_id" as *u8, pos_after_id) 63 gv_kv("read_size" as *u8, sz) 64 gv_kv("pos_after_size" as *u8, pos_after_size) 65 gv_kv("vint_len_0x1A" as *u8, uxr_vint_len(0x1A)) 66 gv_kv("vint_len_0x80" as *u8, uxr_vint_len(0x80)) 67 gv_kv("vint_len_0x01" as *u8, uxr_vint_len(0x01)) 68 gv_kv("vint_len_0x00_malformed" as *u8, uxr_vint_len(0x00)) 69 70 let rc: i64 = gv_verdict("UXF-EBML-GATE" as *u8, ctr, "element ids keep their marker bit and sizes strip theirs, the cursor advances by exactly the vint length in both cases, all eight length classes resolve, and a byte with no marker bit is rejected rather than read as length one" as *u8) 71 sys_exit(rc) 72 return rc 73}