FEX icon indicating copy to clipboard operation
FEX copied to clipboard

Buffer Overflow in LoadFileImpl

Open simon902 opened this issue 10 months ago • 0 comments

The function LoadFileImpl in FEXCore/Source/Utils/FileLoading.cpp line 42 always calls pread with an offset of 0 instead of using CurrentOffset:

while (CurrentOffset != FileSize && (Read = pread(FD, &Data.at(CurrentOffset), FileSize, CurrentOffset)) > 0) {
    CurrentOffset += Read;
}

If the pread function returns fewer bytes than requested (see read(2)) the while loop will get executed again. Since the offset is always 0 data is again read from the beginning of the file. Furthermore, since the destination buffer is indexed via CurrentOffset a (heap) buffer overflow occurs on subsequent pread calls.

Steps to reproduce: On Linux v6.7.0 calling LoadFileImpl on a large file (>= 2.1G) triggers the buffer overflow.

Fix: Replace the offset 0 with CurrentOffset in LoadFileImpl. Also update the FileSize argument to be the number of remaining bytes which still need to be read.

simon902 avatar Feb 05 '26 17:02 simon902