XboxDev / nxdk

The cross-platform, open-source SDK to develop for original Xbox: *new* xdk
437 stars 66 forks source link

cxbe: Fix oob section reads #652

Closed thrimbor closed 1 year ago

thrimbor commented 1 year ago

Fixes regression introduced by https://github.com/XboxDev/nxdk/commit/d6f0f3a24b35f086889c8d8c2c591656e759fdbb.

The underlying issue is that trailing null bytes are not stored in the exe and thus are not part of dwSizeofRaw, causing the null terminator of the xboxkrnl.exe-string to get cut off resulting in an oob-read and invalid string comparison, which ultimately produces an xbe with an incorrect import directory (the hello sample can be used to test this).

I've changed the exe loader and xbe constructor to instead keep the full section in memory so that valid reads from sections can no longer be out of bounds. This slightly increases memory consumption during the conversion, but that shouldn't be an issue.

thrimbor commented 1 year ago

As it's a somewhat critical bugfix and hasn't gotten any more feedback I'll merge it now.