Appendix A — the reproduction model (2 of 2): array sizing, the sweep, and main
Continued from p7. out_cap_for() is the lever that moves the overrun between 62 and 63 bytes; trace_case() drives the non-aborting sweep; main defaults to the canonical case and accepts vuln/fixed/sweep plus optional tail/pad overrides.
/* --- The vulnerable arithmetic, exactly as on page 5 --- */
int64_t output_len = (int64_t)(tail_len / 4) * 3; /* 1-3 byte tail -> 0 */
output_len -= pad; /* "=" -> -1, "==" -> -2 (UNDERFLOW) */
uint64_t mask = bzhi(~0ULL, output_len); /* all-ones when output_len < 0 */
fprintf(stderr, " tail_len=%d pad=%d -> output_len=%lld mask=0x%016llx (%d bits set)\n",
tail_len, pad, (long long)output_len, (unsigned long long)mask,
__builtin_popcountll(mask));
/* The decoded vector (contents irrelevant to the overflow; use a marker). */
uint8_t vec[64];
memset(vec, 0x41 /* 'A' */, sizeof vec);
/* The masked store lands at the tail's output offset: the body (the full
* quads before the tail) has already decoded to STORE_OFF=48 bytes, so the
* store always begins at offset 48 regardless of pad. An all-ones mask
* writes 64 bytes -> offsets 48..111. The array ends at `out_cap` (50 for a
* '=' tail, 49 for '=='), so the OOB count is 111 - out_cap + 1 = 62 or 63. */
size_t store_off = STORE_OFF;
(void)out_cap;
store64_masked(out + store_off, mask, vec);
return (int)output_len;
}
/* Model the output array size for a final fragment of `pad` trailing '='.
* The body (all the full quads before the tail) decodes to STORE_OFF bytes; the
* final quad decodes to (3 - pad) bytes. So the array is STORE_OFF + (3 - pad).
* For the canonical case STORE_OFF=48: pad=1 -> 50 bytes (62 OOB), pad=2 -> 49
* bytes (63 OOB). This is the lever that moves the OOB figure, NOT output_len. */
static size_t out_cap_for(int pad) {
int tail_bytes = 3 - pad; /* '='->2, '=='->1 real bytes in the final quad */
if (tail_bytes < 0) tail_bytes = 0;
return (size_t)STORE_OFF + (size_t)tail_bytes;
}
/* Non-aborting arithmetic trace for one (tail_len,pad) case, used by `sweep`.
* Reports what the mask and OOB count WOULD be, without performing the store. */
static void trace_case(int tail_len, int pad) {
int64_t output_len = (int64_t)(tail_len / 4) * 3 - pad;
uint64_t mask = bzhi(~0ULL, output_len);
size_t out_cap = out_cap_for(pad);
size_t last = (size_t)STORE_OFF + 63; /* last lane of a 64-byte store */
long oob = (long)(last - out_cap + 1); /* offsets out_cap..last */
printf(" tail_len=%d pad=%d | output_len=%2lld | low8=%3llu | mask=%d bits | "
"array=%zu B | would write %ld bytes OOB\n",
tail_len, pad, (long long)output_len,
(unsigned long long)((uint64_t)output_len & 0xFF),
__builtin_popcountll(mask), out_cap, oob);
}
int main(int argc, char **argv) {
const char *mode = (argc > 1) ? argv[1] : "vuln";
if (strcmp(mode, "sweep") == 0) {
/* The documented range: 1-2 byte tails with 1-2 trailing '='. Every row
* underflows to a negative output_len whose low 8 bits are >= 64, so the
* mask is all-ones in every case -- the OOB count varies only with the
* array size (pad), spanning the 62-63 bytes the alert cites. */
printf("CVE-2026-114938 tail-handler sweep (arithmetic only, no store)\n");
trace_case(1, 1); /* canonical Java 21/25: 62 OOB */
trace_case(2, 1);
trace_case(2, 2); /* "==" tail: 63 OOB */
trace_case(3, 1);
printf(" (all rows: mask all-ones -> a 64-byte store; array size sets the OOB count)\n");
return 0;
}
int guard = (strcmp(mode, "fixed") == 0);
/* Default: canonical Java 21/25 case (64 'A' + '=') -> 1-byte tail, pad=1,
* 50-byte array, 62 OOB. Optional argv overrides pick other documented
* cases; the array size is derived from pad so the OOB count is faithful. */
int tail_len = (argc > 2) ? atoi(argv[2]) : 1;
int pad = (argc > 3) ? atoi(argv[3]) : 1;
size_t OUT_CAP = out_cap_for(pad);
printf("CVE-2026-114938 tail-handler model [mode=%s]\n", guard ? "fixed" : "vuln");
printf(" output array: %zu bytes; final fragment: %d byte(s), %d trailing '='\n",
OUT_CAP, tail_len, pad);
uint8_t *out = (uint8_t *)malloc(OUT_CAP); /* heap alloc so ASan knows the bound */
if (!out) return 2;
memset(out, 0, OUT_CAP);
int n = decode_tail(out, OUT_CAP, tail_len, pad, guard);
printf(" decode_tail returned %d; no overflow detected.\n", n);
free(out);
printf(" SURVIVED (mode=%s)\n", guard ? "fixed" : "vuln");
return 0;
}