From 440a56da3b9463d71b91a4a5ca5799880f4eaa4c Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 24 Oct 2026 23:30:31 -0500 Subject: [PATCH] fix(candidate): bind amendment digests to raw manifest bytes Follow-up to #324 under #316. Preserve parser behavior and add exact-byte regression checks. Native execution NOT_RUN; independent static review complete. --- scripts/test_check_candidate.sh | 12 ++++++++++++ tools/candidate/check_candidate.om | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/test_check_candidate.sh b/scripts/test_check_candidate.sh index 36467c4..18e8115 100755 --- a/scripts/test_check_candidate.sh +++ b/scripts/test_check_candidate.sh @@ -98,6 +98,17 @@ amend() { # amend [extra line...] : write CX.amendment-.to MSHA=$(sha256sum "$amd/CX.toml" | cut -d' ' -f1) amend 1 "$MSHA"; expect 0 "amendment: valid amendment accepted" "$amd/CX.toml" "$chk" "$amd/CX.toml" 2>/dev/null | grep -q '(amendments: 1)' && pass=$((pass+1)) || { bad=$((bad+1)); echo "TEST FAIL: amendment file not picked up"; } +# Exact-byte amendment binding: parsing may drop NUL, hashing must not. +cp "$amd/CX.toml" "$amd/CX.raw-orig" +printf '\0' >> "$amd/CX.toml" +expect 1 "amendment: NUL-only frozen manifest edit refused" "$amd/CX.toml" +cp -r "$amd" "$tmp/amdnul" # original digest + altered bytes; retained for the mutant +NULSHA=$(sha256sum "$amd/CX.toml" | cut -d' ' -f1) +[ "$NULSHA" != "$MSHA" ] && pass=$((pass+1)) || { bad=$((bad+1)); echo "TEST FAIL: NUL fixture did not change raw digest"; } +amend 1 "$NULSHA" +expect 0 "amendment: actual raw NUL-containing manifest digest accepted" "$amd/CX.toml" +cp "$amd/CX.raw-orig" "$amd/CX.toml" +amend 1 "$MSHA" amend 1 "$MSHA" "tokenizer-json-sha256 = \"$Z64\""; expect 1 "amendment: all-zero digest in amendment refused (file is read)" "$amd/CX.toml" cp "$amd/CX.toml" "$amd/CX.orig"; amend 1 "$MSHA" echo '# edited after the freeze' >> "$amd/CX.toml"; expect 1 "amendment: frozen manifest edited after amendment refused" "$amd/CX.toml" @@ -131,5 +142,6 @@ mutant "optional pins not checked" '/^optpins$/d' "$tmp/p1.toml" mutant "optional pin sha existence not checked" '/^fn optpin /,/^fn optpins /s/^if not shaex i e$/if false/' "$tmp/p2.toml" mutant "manifest pin not checked" 's/^if not mfeq e$/if false/' "$amd/CX.toml" mutant "amendment may override" 's/^if inmf x$/if false/' "$tmp/amdov/CX.toml" +mutant "raw manifest hash normalized" 's/^sha256$/dropnul\nsha256/' "$tmp/amdnul/CX.toml" echo "passed=$pass failed=$bad" [ "$bad" -eq 0 ] diff --git a/tools/candidate/check_candidate.om b/tools/candidate/check_candidate.om index 6803b7d..0d9f397 100644 --- a/tools/candidate/check_candidate.om +++ b/tools/candidate/check_candidate.om @@ -574,7 +574,6 @@ ret end slurpf int fd r = fclose int fd -dropnul end fn loada to void @@ -1783,9 +1782,11 @@ put pooln 0 0 put failf 0 0 put namend 0 0 loadm +note Bind amendments to the raw frozen file, before parser-only NUL removal. +sha256 +dropnul parse 0 put poolm 0 get pooln 0 -sha256 for i ulong 4 if eq vlen kfind 0 i 0 fail0