Repository navigation
Fix MSan use-of-uninitialized-value in LibArchiveWriter - #97431
Conversation
Fix MSan use-of-uninitialized-value in `LibArchiveWriter::WriteBufferFromLibArchive::closeFile`. The `expected_size` member was not initialized, so if `writeEntry` was never called (e.g. no data written to the buffer), reading `expected_size` in `closeFile` at line 198 triggered the MSan warning. Initialize all non-const non-class-type members at declaration. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=652baa1545bf0933e7a0728edac219ddfe9738f5&name_0=MasterCI&name_1=BuzzHouse%20%28amd_msan%29&name_1=BuzzHouse%20%28amd_msan%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
…chive::closeFile` The test creates a tar archive file entry with known size=0, writes no data, and finalizes the buffer. This exercises the code path where `expected_size` was previously uninitialized, reproducing the MSan error from BuzzHouse CI. Verified that: - Without the fix, MSan catches the exact same error as CI - With the fix, the test passes cleanly under MSan Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes a Memory Sanitizer (MSan) use-of-uninitialized-value bug in LibArchiveWriter::WriteBufferFromLibArchive::closeFile(). The bug occurred when a backup entry declared a file size via writeFile(filename, size) with size=0, but no data was actually written. In this scenario, writeEntry() was never called (it's only invoked when data is written), leaving expected_size uninitialized. When closeFile(true) was later called, it would read the uninitialized value at line 198.
Changes:
- Initialize all class members (
entry,archive,size,expected_size) at declaration inWriteBufferFromLibArchive - Add a gtest that reproduces the exact MSan error scenario with a 0-byte file
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/IO/Archives/LibArchiveWriter.cpp | Initialize member variables at declaration to fix MSan uninitialized value bug |
| src/IO/tests/gtest_archive_reader_and_writer.cpp | Add test case for empty file with known size to verify the fix |
| Entry entry = nullptr; | ||
| Archive archive = nullptr; | ||
| size_t size = 0; | ||
| size_t expected_size = 0; |
There was a problem hiding this comment.
This is the actual fix, but initializing the rest makes sense as a defensive programming measure.
Summary
LibArchiveWriter::WriteBufferFromLibArchive::closeFileby initializing all class members at declarationEmptyFileWithKnownSize) that reproduces the exact MSan error — verified it fails without the fix and passes with itThe bug was triggered by BuzzHouse running incremental
BACKUPqueries to tar archives. When a backup entry announced a file size viawriteFile(filename, size)but no data was actually written (0 bytes copied),writeEntrywas never called, leavingexpected_sizeuninitialized. ThencloseFile(true)read it.https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=652baa1545bf0933e7a0728edac219ddfe9738f5&name_0=MasterCI&name_1=BuzzHouse%20%28amd_msan%29&name_1=BuzzHouse%20%28amd_msan%29
Closes #97492
Test plan
Changelog category
CI Fix or improvement
Changelog entry
Fix MSan use-of-uninitialized-value in
LibArchiveWriter::WriteBufferFromLibArchive::closeFileby initializing class members at declaration.🤖 Generated with Claude Code
Version info
26.2.1.1035