Avoid squirrelly memcpy() call in filesystem.cpp by StephanTLavavej · Pull Request #4933 · microsoft/STL (original) (raw)

We have an extremely squirrelly line of code that's memcpying two consecutive DWORDs into the beginning of a buffer. There's no reason for this weirdness - it isn't perf-critical, and the optimizer should understand memcpy. Now, code analysis tools (specifically CodeQL) are noticing that this code is a 🐿️ read overrun. Let's avoid this by splitting it up into two separate reads.

For the destination, _Id points to FILE_ID_INFO. Its FileId is FILE_ID_128, which contains BYTE Identifier[16];.

For the source, _Info is BY_HANDLE_FILE_INFORMATION:

typedef struct _BY_HANDLE_FILE_INFORMATION { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD dwVolumeSerialNumber; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD nNumberOfLinks; DWORD nFileIndexHigh; DWORD nFileIndexLow; } BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION, *LPBY_HANDLE_FILE_INFORMATION;