Repository navigation
Prevent source data loss when conversion input and output refer to the same file - #885
Open
Jaeyou PARK (cpuu) wants to merge 1 commit into
Open
Jaeyou PARK (cpuu) wants to merge 1 commit into
Jaeyou PARK (cpuu) wants to merge 1 commit into
Conversation
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.
Converting an image with the same input and output file currently truncates the source before reading it. Different paths that are hard links to the same file can cause the same data loss.
For forensic workflows, accidentally selecting the source as the output should not destroy the evidence being processed. This PR rejects that operation before truncation and reports an error asking the user to choose a different output path. An explicit failure also works in unattended workflows without requiring an interactive prompt.
Existing checks do not prevent this case:
NoConversionRequiredrejects matching formats, not matching files; UnixO_NOFOLLOWrejects output symlinks but not identical paths or hard links; and input canonicalization does not compare source and destination identities. The payload checks added in #884 run after the destination has already been opened with truncation.The change opens the destination without truncation, compares the identities of the already-open source and destination files using
same-file, and truncates a regular destination only after confirming that it is distinct. Existing Unix output-symlink rejection and support for non-regular destinations are preserved.Regression tests cover:
/dev/nulloutput.On the unmodified baseline (
78113519), two new tests fail because the source becomes empty. With this change, all 30 library tests, 6 conversion tests, and 4 new integration tests pass on Linux aarch64. Formatting and scoped strict Clippy checks also pass.