code wiki / (root) / nx_fetch_capacity_gate_t253.nx

nx_fetch_capacity_gate_t253.nx source

↩ module page · 38 lines · 2591 B

1// Native replay of retained real gzip plus capacity and corruption boundaries. 2// ISIZE is a test observation, never allocation authority; caller supplies budget. 3import "nx_fetch_status_live_gate_t252.nx" 4func dc_check(got:i64,want:i64,name:*u8)->i64{fa_puts(name);fa_puts(" got=");fa_putn(got);fa_puts(" want=");fa_putn(want);fa_puts("\n");return (got!=want) as i64} 5func main(argc:i64,argv:*i64)->i64{ 6 if argc!=3{return 2};let budget:i64=hsl_size(argv[2] as *u8);if budget<=0{return 2} 7 let ln:*i64=sys_mmap_try(8) as *i64;let src:*u8=sys_map_file(argv[1] as *u8,ln) 8 if (src as i64)==0{return 3};if ln[0]<18{return 3} 9 let good:*NxGzipResult=nx_gzip_inflate(src,ln[0],budget) 10 var bad:i64=dc_check(good.error_code,0,"real gzip valid") 11 if good.error_code!=0{return 4} 12 let size:i64=good.output_size 13 bad=bad+dc_check(good.bytes_consumed,ln[0],"all compressed consumed") 14 bad=bad+dc_check(good.crc_computed,good.crc_expected,"CRC matches") 15 let small:*NxGzipResult=nx_gzip_inflate(src,ln[0],size-1) 16 bad=bad+dc_check(small.error_code,NX_GZ_ERR_OUTPUT_CAPACITY,"gzip capacity") 17 let header:*u8="HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\n\r\n" 18 let he:i64=_gc_slen(header);let rn:i64=he+ln[0];let raw:*u8=sys_mmap_try(rn) 19 var i:i64=0;while i<he{raw[i]=header[i];i=i+1};i=0;while i<ln[0]{raw[he+i]=src[i];i=i+1} 20 let out:*u8=sys_mmap_try(he+size) 21 bad=bad+dc_check(hf_decode_transport(raw,rn,out,size-1),HF_DEC_CAPACITY,"fetch body capacity") 22 bad=bad+dc_check(hf_decode_transport(raw,rn,out,size),HF_DEC_CAPACITY,"fetch headers capacity") 23 let n:i64=hf_decode_transport(raw,rn,out,he+size) 24 bad=bad+dc_check(n,he+size,"fetch exact decoded size") 25 if n==he+size{var dif:i64=0;i=0;while i<size{if out[he+i]!=good.output_data[i]{dif=dif+1};i=i+1};bad=bad+dc_check(dif,0,"decoded byte equality");bad=bad+dc_check(hfd_hdr_enc(out,he),0,"coding header retired")} 26 raw[rn-8]=raw[rn-8]^(1 as u8) 27 bad=bad+dc_check(hf_decode_transport(raw,rn,out,he+size),HF_DEC_INFLATE,"corrupt CRC distinct") 28 let z:*u8=sys_mmap_try(13) 29 z[0]=120;z[1]=1;z[2]=1;z[3]=2;z[4]=0;z[5]=253;z[6]=255;z[7]=72;z[8]=105;z[9]=0;z[10]=251;z[11]=0;z[12]=178 30 let zr:*NxZlibResult=nx_zlib_inflate(z,13,1) 31 bad=bad+dc_check(zr.error_code,NX_ZLIB_ERR_OUTPUT_CAPACITY,"zlib stored capacity") 32 let zok:*NxZlibResult=nx_zlib_inflate(z,13,2) 33 bad=bad+dc_check(zok.error_code,0,"zlib exact capacity") 34 let dr:*NxDeflateResult=nx_deflate_inflate(z+2,7,1) 35 bad=bad+dc_check(dr.error_code,NX_DEF_ERR_OUTPUT_CAPACITY,"raw stored capacity") 36 fa_puts("capacity_boundary_failures=");fa_putn(bad);fa_puts("\n") 37 return (bad!=0) as i64 38}