Skip to content

Commit 7316ef4

Browse files
Godsdarvondele
authored andcommitted
Reject oversized Syzygy symbol tables
`set_sizes()` reads the symbol count from the tablebase as a `u16`, but `btreeBuf`, `symlen` and `colour` have only `SymCount` (4096) entries. The existing `fits()` check bounds the source bytes, so a malformed table with a larger count can pass that check and overrun the destination in `memcpy()` and the subsequent symbol loop. Reject counts greater than `SymCount` through the existing corrupt-table path before copying or iterating. Counts up to and including `SymCount` keep their existing handling. This applies to both WDL and DTZ loading. Validation on macOS arm64 with Apple Clang: - Optimized Apple silicon build; changed translation unit compiled with `-Werror`. - All 75 upstream instrumented tests passed on a debug build with AddressSanitizer and UndefinedBehaviorSanitizer, including the Syzygy tests. - Baseline and patched default benches both searched 1,559,611 nodes. - `tests/signature.sh 1559611` and `git diff --check` passed. The bounds error was identified and checked by source inspection; a malformed-tablebase runtime reproducer was not run. Windows and Linux validation remain for CI. Prepared with OpenAI Codex, including source analysis and testing. No functional change for valid tablebases. closes #7237 No functional change
1 parent 90fbc48 commit 7316ef4

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎src/syzygy/tbprobe.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ u8* set_sizes(PairsData* d, u8* data, const u8* end) {
12081208
const usize symlenSize = number<u16, LittleEndian>(data);
12091209
data += sizeof(u16);
12101210

1211-
if (!fits(data, symlenSize, sizeof(LR), end))
1211+
if (symlenSize > SymCount || !fits(data, symlenSize, sizeof(LR), end))
12121212
return nullptr;
12131213

12141214
d->btreeBuf.assign(SymCount, LR{{0x00, 0xF0, 0xFF}});

0 commit comments

Comments
 (0)