script: keep metablock parity harness distances valid

Clamp the synthetic commands' distance codes to the distance params'
max_distance, as the encoder does. Larger (invalid) distances made the C
code's ComputeDistanceCost write past the end of its distance histogram,
which showed up as a spurious mismatch for a large-window configuration.
This commit is contained in:
Claude committed 2026-10-27 01:26:30 +00:00
1 parent 5393d92234
commit 132445a5e6
1 file changed
+8
@@ -455,6 +455,14 @@ static size_t //
random_distance(block_t* b) {
uint32_t r = rng_below(16);
size_t max = b->large_window ? 0x7FFFFFFC : ((1u << 24) - 16);
// Keep the distance codes (distance + 15) at most the distance params'
// max_distance (which is less than 0x7FFFFFFC for some large-window
// params), as the encoder does. Larger distances are invalid for those
// params and make the C code's ComputeDistanceCost write past the end of
// its distance histogram.
if (max > (b->dist.max_distance - 15)) {
max = b->dist.max_distance - 15;
}
if ((g_dist_style == 1) && (r < 12)) {
// Distances with a fixed residue modulo (1 << g_dist_shift), which
// favors npostfix > 0.