Skip to content

Clamp enumByteSize read count to prevent global buffer overflow - #1232

Open
acato wants to merge 1 commit into
We-the-People-civ4col-mod:developfrom
acato:fix/savegame-enumbytesize-overflow
Open

Clamp enumByteSize read count to prevent global buffer overflow#1232
acato wants to merge 1 commit into
We-the-People-civ4col-mod:developfrom
acato:fix/savegame-enumbytesize-overflow

Conversation

@acato

@acato acato commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Clamps the iSize byte read from the savegame to NUM_SAVEGAME_CLASS_TYPES (23) before using it as a loop bound for writing into the enumByteSize global array
  • Without this check, a crafted savegame sets iSize up to 255, overwriting 232 bytes of adjacent globals — including the conversion table that controls all subsequent deserialization

Fixes #1229

Test plan

  • Load an existing savegame — verify it loads identically to before
  • Save and reload mid-game — verify no data loss
  • Confirm the fix compiles cleanly in Assert, Release, and FinalRelease targets

🤖 Generated with Claude Code

The savegame reader writes attacker-controlled bytes into the
enumByteSize[NUM_SAVEGAME_CLASS_TYPES] global array using a byte
count read from the savegame (0-255), but the array only has 23
entries. A crafted savegame overwrites adjacent globals, corrupting
the conversion table and enabling controlled memory corruption.

Fixes We-the-People-civ4col-mod#1229

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: enumByteSize global buffer overflow via crafted savegame

1 participant