Repository navigation
fix(programs): identify the input file by identity on Windows - #4861
Open
Huang-404-Q wants to merge 1 commit into
Open
Huang-404-Q wants to merge 1 commit into
Huang-404-Q wants to merge 1 commit into
Conversation
UTIL_isSameFile and UTIL_isSameFileStat fall back to strcmp on Windows, so alternate spellings of the same path (case variants, ./ prefixes, absolute paths, hard links) are treated as different files. FIO_openDstFile then opens the output with O_TRUNC and destroys the input before it is read. Compare the volume serial number and file index from GetFileInformationByHandle instead, which identifies the file regardless of how the path is spelled. Adds a CLI test that compresses a file onto itself via ./file and checks the input is left intact.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.Suggestion cannot be applied right now. Please check back later.
What
On Windows,
UTIL_isSameFile/UTIL_isSameFileStatfall back tostrcmp, so any alternate spelling of the same path (case variant,./prefix, absolute vs relative, 8.3 name, hard link) is considered a different file.FIO_openDstFile()then opens that path withO_TRUNC, destroying the already-open source before it is read.Repro with a 30000-byte
a.binon Windows:The exact-spelling control
-o a.bincorrectly refuses.Fix
Under
_WIN32, compare the volume serial number and file index fromGetFileInformationByHandleinstead of the path strings.UTIL_isSameFileStatuses the same helper. Non-Windows paths are unchanged.Verification
Built
programs/zstdwith MinGW gcc 13.2 and ran the cases:a.binA.bin(case variant)./a.binout.zstAlso added
tests/cli-tests/file-stat/compress-file-to-itself.sh, which uses./file(the same path on every platform) and checks the input is unchanged. The local CLI test runner could not run on this Windows host because it creates symlinks (WinError 1314); the exact commands were verified manually as above.