Repository navigation
write: report close callback failures from archive_write_close() - #3749
Merged
DHowett merged 2 commits intoOct 27, 2026
Merged
Conversation
archive_write_open(3) says that the close callback should return ARCHIVE_FATAL on failure. Check that archive_write_close() and archive_write_free() report that status, keep the error set by the callback, and do not invoke the callback a second time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
archive_write_client_close() invoked the client close callback but ignored its return value, so archive_write_close(), and archive_write_free() when it closes the archive, returned ARCHIVE_OK even when the callback returned ARCHIVE_FATAL as archive_write_open(3) asks it to on failure. The error set by the callback was left in place, so the failure was only visible to a caller that checked archive_errno() after a close that reported success. The status was lost in 2010: 992610f moved the output blocking into archive_write_client_close() and dropped the closer call, and 4739b8d added the call back without its return value. Merge the callback's status into the value returned by archive_write_client_close(), as client_close_proxy() already does for the close callback on the read side. Fixes #1713 Co-Authored-By: Claude Opus 5.5 <[email protected]>
DHowett
approved these changes
Oct 27, 2026
mmatuska
pushed a commit
to mmatuska/libarchive
that referenced
this pull request
Oct 29, 2026
…lose-callback-error write: report close callback failures from archive_write_close() (cherry picked from commit bad49b7)
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 #1713.
archive_write_client_close()calls the client close callback but ignores its return value. As a resultarchive_write_close()returnsARCHIVE_OKeven when the callback returnsARCHIVE_FATAL, which archive_write_open(3) tells a close callback to return on failure.archive_write_free()behaves the same way when it closes the archive itself. The error the callback set witharchive_set_error()stays in place, so a caller only sees the failure if it checksarchive_errno()after a close that reported success. If the close callback does the final flush or upload, a failed write is reported as a finished archive.The status used to be returned. In 911dc2b,
archive_write_client_close()returned the callback's value. 992610f replaced the function body with the output blocking code and dropped the call, and 4739b8d added the call back without its result. On the read side,client_close_proxy()already merges the close callback's status.This change merges the callback's status into the value
archive_write_client_close()returns, so the caller gets the worse of the final block write and the close callback. The callback still runs only once:__archive_write_filters_close()marks the client filter as failed, and a laterarchive_write_free()does not call it again. The built-in helpers behave as before. The close callback ofarchive_write_open_filename()ignores the result of close(2) and returnsARCHIVE_OK, and the fd,FILE *and memory helpers do not register one. bsdtar, bsdcpio and the other tools are therefore unaffected.The first commit adds
test_archive_write_close_callback, and the second commit is the fix. The test opens a ustar writer whose close callback returns a chosen status and setsEIOwhen that status is notARCHIVE_OK. It checks whatarchive_write_close()andarchive_write_free()return, that the callback's error is kept, and that the callback runs once.Verification on macOS (Apple clang 21, CMake + Ninja, Debug build without liblzma, zstd and lz4):
libarchive_test test_archive_write_close_callbackfails 3 assertions:archive_write_close()returns 0 instead ofARCHIVE_FATAL, with errno 5 and the callback's message set.archive_write_free()with no earlier close returns 0 instead ofARCHIVE_FATAL.ARCHIVE_WARNfrom the callback is returned as 0.archive_write_close: -30instead of0.libarchive_test: 952 tests ran and 3 failed.test_read_format_zip_lzma_alone_large_sizefails because liblzma is not enabled.test_write_disk_permsandtest_write_disk_securefail because the sandbox the tests ran in does not allow setuid/setgid bits or writes to/tmp. All three fail the same way without this change.bsdtar_test(80 tests),bsdcpio_test(49),bsdcat_test(18) andbsdunzip_test(30) all pass.🤖 Generated with Claude Code