fix(index): validate num_pages when loading RTree metadata - #8988
Open
jackylee-ch wants to merge 1 commit into
Open
fix(index): validate num_pages when loading RTree metadata#8988jackylee-ch wants to merge 1 commit into
jackylee-ch wants to merge 1 commit into
Conversation
num_pages is read back from index metadata and load validates page_size but never num_pages. A search walks down from num_pages - 1, so a value that disagrees with num_items and page_size does not fail: zero underflows and every page range comes back empty, while a low value truncates the walk. A 200-item index answered 0 rows for an unreadable value and 8 rows for an off-by-one one. Validate the raw metadata before constructing RTreeMetadata, because its constructor already debug_asserts the same equality and would panic before the error could surface. An absent key is derived from num_items and page_size, which is how the format spec computes every page offset, so a conforming index that omits it still loads.
jackylee-ch
force-pushed
the
fix/rtree-num-pages-validation
branch
from
September 4, 2026 10:32
1b71b21 to
e13be63
Compare
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
Both prior metadata-loading findings are fixed. The loader now validates a present stored page count before constructing the asserted representation, derives the count when the optional key is absent, and the focused load-path tests cover corrupt, absent, consistent, and degenerate metadata.
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.
num_pagesis read back from index metadata andloadvalidatespage_sizebut nevernum_pages. A search walks down fromnum_pages - 1, so a value that disagrees withnum_itemsandpage_sizedoes not fail — it answers the wrong rows:Validation runs on the raw metadata, before
RTreeMetadatais constructed: its constructor alreadydebug_assert!s the same equality, so validating afterwards would panic in debug builds instead of returning the error. An absent key is derived fromnum_itemsandpage_size— the format spec computes every page offset from those two — so a conforming index that omits it still loads.