Repository navigation
librepgp: report errors on short writes to file outputs - #2591
Merged
Merged
Conversation
file_dst_write() treated any non-negative write() return as success, so a short write (full filesystem, file size limit) silently dropped the remaining data and reported success, leaving a truncated file: a saved keyring could be cut short with rnp_save_keys() and rnp_output_finish() succeeding (found by Misja Hoebe, #2590). Write the remainder in a loop instead, and propagate a write error from dst_finish() so rnp_output_finish() reports it; do not run the finish callback (such as renaming a temporary output file over the target one) when the data was not written in full.
This was referenced Nov 24, 2026
1 task done
Contributor
Author
|
@kwkwan two quick ones when you have a moment:
Thank you! |
kwkwan
approved these changes
Nov 26, 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.
Fixes #2590.
Summary
The function file_dst_write() in src/librepgp/stream-common.cpp treated any non-negative return of write() as success. When write() completes partially, for example on a full filesystem or when a file size limit is hit, the remaining data was silently dropped and RNP_SUCCESS was returned. As a result, rnp_save_keys() and rnp_output_finish() succeeded while the file was truncated and the saved keys were lost. Many thanks go to @misja for the precise report and the minimal reproducer.
Fix
Verification
Test plan