Repository navigation
Preserve destination files when saving fails - #165
Merged
Merged
Conversation
This was referenced Oct 15, 2026
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.
FreeImage_Save previously opened the destination with
w+bbefore encoding, so an encoder failure destroyed an existing file. Stage output in an exclusively created sibling temporary file and replace the destination only after encoding and fclose succeed. Failed encodes, stream errors, close failures, and rename failures clean up the temporary file.Adapt the staged-save approach described in FreeImageRe 4.2.0 without importing its C++20 filesystem implementation. Keep narrow and Windows Unicode entry points; SaveToHandle remains caller-owned. POSIX special files and symlink destinations are rejected. New POSIX files are private (0600); existing regular-file permissions are preserved. Replacement changes hard-link semantics and is not a power-loss durability guarantee.
Tests: a custom encoder writes partial output then fails; the pre-fix library replaces the original with
incomplete, while the fixed build preserves it. Test missing destinations, invalid formats, header-only saves, successful PNG replacement, and Windows Unicode paths. Update the old header-only test to check Save's return value rather than reading a stale destination. macOS C++11 AddressSanitizer build and all three CTest suites pass. Windows and Linux coverage runs in existing CI.PR stack
Root PR, based on
master. Next: #166.#165 → #166 → #167 → #168 → #169 → #170 → #171
Merge bottom-up. Each PR diff is relative to its predecessor. Combined stack validation passed locally: 10 CTest suites with ASan, 9 in a shared build, 6 with both optional codecs disabled, plus all four Python/NumPy test groups. GitHub CI reruns after the branch rewrite.