Add freeze MPQ unit tests and fix 64-bit memory bugs - #178
Merged
Merged
Conversation
- Add mpq_unit_tests target (doctest): crypt/keycalc known-answer, roundtrip, determinism/guard, garbagify, and compression tests - Fix heap overflow in PKWARE explode/implode work buffers on 64-bit (structs outgrew EXP/CMP_BUFFER_SIZE); add fit asserts - Fix uLong/LPDWORD width mismatch in Deflate/Inflate (LP64) - Harden keycalc/GetFileDecryptKey inputs, RAII decrypt buffer, deterministic garbagify overload for tests - CI: run mpq unit tests on Windows/macOS/Ubuntu per push and PR
doctest has no std::string overload, so CHECK(str == str) instantiates operator<<(ostream, string), which fails to link on some toolchains (Xcode Clang). Compare via size + memcmp instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
mpq_unit_teststarget (doctest) for the freeze MPQ code and fixes thereal bugs the new tests exposed. CI runs it on Windows/macOS/Ubuntu per push and PR.
Tests
mpq/test/test_keycalc_crypt.cpp:T/mixknown answers,mix/unmixroundtrip,
HashStringsemantics,Encrypt/Decryptroundtrip,GetFileDecryptKeyrecovery,keycalcdeterminism + input guards,deterministic
garbagifyoverload.into CMake) — and it caught a heap overflow on first run.
test_cmpdcmp.cpp: compare via size +memcmpinstead ofCHECK(str == str);doctest has no
std::stringoverload, so the latter instantiatesoperator<<(ostream, string), which fails to link on Xcode Clang.Fixes (behavior-preserving except the overflow)
explode/implodeon 64-bit: the work structsassume 32-bit
long/pointers and outgrewEXP_BUFFER_SIZE/CMP_BUFFER_SIZE.Buffers enlarged with compile-time fit asserts (
exp.c,imp.c,pklib.h).uLong/LPDWORDwidth mismatch inDeflate/Inflate(scomp.cpp):casting 32-bit
LPDWORDto 64-bitunsigned long*corrupts memory on LP64.Now bounces through a
uLongtemp.keycalc: null/tiny-table/zero-sector guards (throw instead of UB),explicit wrapping-arithmetic docs + fixed bit-identity notes vs
freeze/.GetFileDecryptKey: RAII buffer (exception-safe), null check,memcpyinstead of unaligned
uint32_t*dereference.garbagifyHashTable: deterministic(table, max, gen&)overload for tests;production path unchanged (still
random_device).getFileCount/getBlockEntryCountdeclarations;catch (const std::exception&)instead of slicingcatch (runtime_error);system("pause")is_WIN32-only.CI
.github/workflows/test.yml: builds + runsmpq_unit_testson the3-OS matrix using a bare
uv venv(no full dep sync needed).FREEZE_BUILD_TESTSoption (default ON) inmpqprt/CMakeLists.txt.Verification
mpq_unit_tests: 8/8 cases, 61/61 assertions pass (also clean under ASan).lib/freezeMpq.sorebuilt with Python 3.14t; fulled_profilerun passes(9.25s, no regression vs 9.23s before).