If the dwFileAttributes member includes the FILE_ATTRIBUTE_REPARSE_POINT attribute, this member specifies the reparse point tag.
Otherwise, this value is undefined and should not be used.
reparse_tag_from_INFO uses dwReserved0 without checking the FILE_ATTRIBUTE_REPARSE_POINT attribute, which causes directory_iterator to use a stale dwReserved0 value for all files subsequent to a symlink, causing all of these files to be treated as symlink incorrectly.
This patch checks FILE_ATTRIBUTE_REPARSE_POINT before checking dwReserved0 to correctly get the symlink status of the files. Also replaced a hack that uses structure size to determine structure type with proper templates.
According to microsoft documentation on the
dwReserved0
member of_WIN32_FIND_DATAW
,reparse_tag_from_INFO
usesdwReserved0
without checking theFILE_ATTRIBUTE_REPARSE_POINT
attribute, which causesdirectory_iterator
to use a staledwReserved0
value for all files subsequent to a symlink, causing all of these files to be treated as symlink incorrectly.This patch checks
FILE_ATTRIBUTE_REPARSE_POINT
before checkingdwReserved0
to correctly get the symlink status of the files. Also replaced a hack that uses structure size to determine structure type with proper templates.This patch is tested on https://github.com/CleverRaven/Cataclysm-DDA/pull/63612 and cherrypicked from that PR.