Repository navigation
fix ScanTable causing assertion failure in Encode - #1344
Open
yvonnelxxxx wants to merge 1 commit into
Open
yvonnelxxxx wants to merge 1 commit into
yvonnelxxxx 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.
This PR attempts to fix #1343
Problem
Repairer::ScanTable()indb/repair.ccscans a table to derive itssmallest/largestInternalKeys. When a corrupted table opens successfully (iterator status OK) but every key failsParseInternalKey(), theemptyflag staystrueandt.meta.smallest/t.meta.largestare never populated — they remain default-constructed (emptyrep_).Despite that, the old code pushed the table straight into
tables_:Later,
WriteDescriptor()callsedit_.AddFile(0, ..., t.meta.smallest, t.meta.largest)for every entry, andVersionEdit::EncodeTo()(db/version_edit.cc:82) serializes them viaf.smallest.Encode()/f.largest.Encode(). That hits:at
db/dbformat.h:150and aborts:Stack:
This is a realistic corruption scenario: zeroing the data-block region of an SST while leaving the index + footer intact lets
Table::Opensucceed, so the iterator is "OK" but yields no parseable keys.Fix
In
ScanTable(), gate the push on!empty. If the table opened but produced no valid keys, archive it instead of passing empty key bounds downstream toWriteDescriptor:This keeps the existing path for tables with valid keys unchanged, and routes keyless-but-OK tables through the same
ArchiveFilemechanism already used for unreadable files (the "dropped" branch above). An alternative would be to weaken theassert(!rep_.empty())inInternalKey::Encode(), but that would let empty key bounds be silently written into the manifest — a worse outcome than dropping the corrupt table, so archiving is preferred.Verification
Sanitizer rebuild
Rebuilt the library with AddressSanitizer and UndefinedBehaviorSanitizer to confirm the assertion crash is gone and no memory/UB issues remain:
Before fix:
After fix:
(clean exit, code 0 — no sanitizer errors)
Test-suite results
Ran the full LevelDB test suite under ASan + UBSan with
halt_on_error=1:leveldb_tests(211 tests)c_test(incl.Test repair)env_posix_test(7 tests)All tests pass with the fix applied.