From 42adfb03eecf8192094c510374d3b04370aedb66 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 22 Sep 2026 12:15:26 +0200 Subject: [PATCH] Make content, hash and no-op comparisons case-sensitive Every hash comparison in the script (sidecar verification, mutant verification, restore verification: Assert-TargetUnedited, Restore- Targets, the startup repair loop, and M0) used PowerShell's plain -eq/ -ne, which is case-insensitive. Hashes are hex strings where case never carries meaning here (Get-Hash and Get-BytesHash always produce a fixed case each), so this was latent, not exploitable -- but it left every "is this file still what I think it is" check one string-comparison operator away from silently accepting a corrupted file whose hex happened to differ only in case. Switched all eight sites to -ceq/-cne. Hash case is chosen to matter, both for defence in depth and because these functions are the harness's only proof that a restore or a mutant write landed the intended bytes. The no-op guard that rejects a mutation whose old and new text come out identical also used -eq: `if ($old -eq $new)`. Under case-insensitive comparison a mutant that differs from the source only in case, such as `"query"` to `"Query"`, compared equal and was refused as a no-op even though it is a real source change. Switched to -ceq. Anchor matching (Measure-Sites, and the splice-site IndexOf that follows it) already used [System.StringComparison]::Ordinal, which is case-sensitive; checked and left unchanged. Demonstrated in a scratch repo (demo-case) with a single-mutation suite whose only edit is `"query"` -> `"Query"` against `fn f() -> query { 1 }`, and a fake test command that fails unless the unmutated lowercase text is present (i.e. is killed by the mutation). Before: "CaseDemo: replacement changes nothing in t.txt.", exit 1, mutation never ran. After: the mutation runs, the fake test fails against the mutated text, verdict "killed", M0 green, exit 0. Co-Authored-By: Claude Sonnet 5 --- tools/eureka-mutations.ps1 | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/eureka-mutations.ps1 b/tools/eureka-mutations.ps1 index a250e1a..71ff833 100644 --- a/tools/eureka-mutations.ps1 +++ b/tools/eureka-mutations.ps1 @@ -83,6 +83,13 @@ # repair refuses to run at all while any such marker exists, prints what to # reconcile, and touches nothing, rather than mistaking a deliberate stop # for a crash and reverting a hand-cleaned file out from under an operator. +# - Every hash comparison in this script (sidecar, mutant and restore +# verification) is a case-sensitive ordinal compare (`-ceq`/`-cne`), and so +# is the no-op guard that rejects a mutation whose old and new text come +# out identical: PowerShell's plain `-eq`/`-ne` are case-insensitive, which +# let a mutant differing only in case (`"query"` to `"Query"`) be rejected +# as a no-op. Anchor matching (`Measure-Sites`, and the splice site lookup +# that follows it) already used ordinal `IndexOf` and needed no change. # - M0 is built in and cannot be omitted: before any entry, every target's # bytes are decoded and re-encoded through the harness I/O path and compared # to the original bytes before anything is written. If a byte differs, the @@ -200,8 +207,8 @@ function Assert-TargetUnedited([string] $file, [string] $mutantHash) { $path = $targets[$file] if (-not (Test-Path -LiteralPath $path)) { return } $current = Get-Hash $path - if ($current -eq $hashes[$file]) { return } - if ($mutantHash -and $current -eq $mutantHash) { return } + if ($current -ceq $hashes[$file]) { return } + if ($mutantHash -and $current -ceq $mutantHash) { return } $overwritten = Get-UniqueOverwrittenPath $path [System.IO.File]::WriteAllBytes($overwritten, [System.IO.File]::ReadAllBytes($path)) $message = "EDIT LOST: $path (SHA-256 $current) is neither the M0 original ($($hashes[$file])) nor this entry's own mutant. Something edited it outside the harness while a run was in flight or between entries. Its bytes are kept in $overwritten. Stopping the run rather than silently discarding them." @@ -231,10 +238,10 @@ function Restore-Targets([string[]] $files, [hashtable] $mutantHashes = @{}) { $path = $targets[$file] try { Assert-TargetUnedited $file $mutantHashes[$file] - if ((Get-Hash $path) -ne $hashes[$file]) { + if ((Get-Hash $path) -cne $hashes[$file]) { [System.IO.File]::WriteAllBytes($path, $bytes[$file]) } - if ((Get-Hash $path) -ne $hashes[$file]) { + if ((Get-Hash $path) -cne $hashes[$file]) { throw "writing the original bytes back did not restore $file; it does not hash to the original." } Remove-Item -LiteralPath (Get-SidecarPath $path) -Force -ErrorAction SilentlyContinue @@ -373,7 +380,7 @@ foreach ($sidecar in $sidecars) { # its bytes, so there is nothing to compare and nothing to keep. if (-not (Test-Path -LiteralPath $path)) { [System.IO.File]::WriteAllBytes($path, $original) - if ((Get-Hash $path) -ne $hash) { + if ((Get-Hash $path) -cne $hash) { throw "recreating it from $sidecar did not land the original bytes (SHA-256 $hash)." } Remove-Item -LiteralPath $sidecar -Force @@ -406,7 +413,7 @@ foreach ($sidecar in $sidecars) { } throw "the restore changed the file before failing; its pre-repair bytes (SHA-256 $(Get-BytesHash $current)) are kept in $overwritten. $_" } - if ((Get-Hash $path) -ne $hash) { + if ((Get-Hash $path) -cne $hash) { throw "restoring it from $sidecar did not land the original bytes (SHA-256 $hash); its pre-repair bytes (SHA-256 $(Get-BytesHash $current)) are kept in $overwritten." } Write-Host "The bytes $path held before the repair (SHA-256 $(Get-BytesHash $current)) are kept in $overwritten." @@ -446,7 +453,7 @@ foreach ($file in $Target) { [System.IO.File]::WriteAllBytes((Get-SidecarPath $path), $original) try { Write-Text $path $text - if ((Get-Hash $path) -ne $hash) { + if ((Get-Hash $path) -cne $hash) { throw "harness broken: writing $file through the harness I/O path did not land the re-encoded bytes; the original bytes were written back. No entry ran." } } @@ -482,7 +489,7 @@ foreach ($mutation in $suite) { if ($sites -ne 1) { throw "$($mutation.Id): anchor matches $sites times in $($edit.File), expected exactly 1." } - if ($old -eq $new) { throw "$($mutation.Id): replacement changes nothing in $($edit.File)." } + if ($old -ceq $new) { throw "$($mutation.Id): replacement changes nothing in $($edit.File)." } # Spliced by position at the one site, so the replacement need not be # unique (`Ok(())` is not) or non-empty. $at = $texts[$edit.File].IndexOf($old, [System.StringComparison]::Ordinal)