Common/FileUtil: Fix incorrect (32-bit) stat struct being used on Windows, which was hidden by a define in CommonFuncs.h. #10183
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.
tldr: https://godbolt.org/z/9YeK6fToa
This is a really silly name clash between the
statstruct, the_stat64struct, and a#definethat tries to make thestatfunction work on Windows by mapping the_stat64function to it.Over in FileUtil.h we have a member of FileInfo that is defined as follows:
dolphin/Source/Core/Common/FileUtil.h
Line 123 in 2a34b84
And over in CommonFuncs.h we have this define:
dolphin/Source/Core/Common/CommonFuncs.h
Line 29 in 2a34b84
Additionally,
sys/stat.hon Windows defines the following structs:This is a problem. If you include
FileUtil.hwithout includingCommonFuncs.h, you get the second struct but if you includeCommonFuncs.hyou instead get the first struct.FileUtil.cppdoes the latter, so it gets the_stat64struct. This means that different compilation units may have a different idea about the length ofFile::FileInfo, leading to potential stack corruption.Note that I'm using
__stat64here instead of_stat64because that's how the_wstat64function (which we use) is defined in the MSVC docs: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=msvc-160...I love code that works by accident.