fix: prevent panic when reading empty WAL index file (#737)#912
Merged
mattisonchao merged 1 commit intomainfrom Feb 26, 2026
Merged
fix: prevent panic when reading empty WAL index file (#737)#912mattisonchao merged 1 commit intomainfrom
mattisonchao merged 1 commit intomainfrom
Conversation
When the .idxx index file is empty (0 bytes), ReadIndex() would panic with "slice bounds out of range [4:0]" when trying to read the CRC at offset 0. This fix adds a length check before reading the index. If the file is shorter than the header size (4 bytes), it returns ErrDataCorrupted instead of panicking, allowing the caller to rebuild the index from the txn file. Added tests: - TestV2_ReadEmptyIndex: verifies empty file handling - TestV2_ReadShortIndex: verifies short file (<4 bytes) handling Fixes #737
mattisonchao
approved these changes
Feb 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.
Problem
When the .idxx index file is empty (0 bytes),
ReadIndex()would panic withslice bounds out of range [4:0]when trying to read the CRC at offset 0.Stack trace from #737:
Solution
Added a length check before reading the index. If the file is shorter than the header size (4 bytes), it returns
ErrDataCorruptedinstead of panicking, allowing the caller (readonly_segment.go) to rebuild the index from the txn file.Changes
oxiad/dataserver/wal/codec/v2.go: Added length check inReadIndex()oxiad/dataserver/wal/codec/v2_test.go: Added tests for empty and short index filesTest Plan
Both tests pass:
TestV2_ReadEmptyIndex: verifies empty file (0 bytes) returnsErrDataCorruptedTestV2_ReadShortIndex: verifies short file (<4 bytes) returnsErrDataCorruptedFixes #737