Repository navigation
docs(encoded_s2shape_index): state the trusted-input assumption on Init - #686
Open
sushant-me wants to merge 1 commit into
Open
sushant-me wants to merge 1 commit into
sushant-me wants to merge 1 commit into
Conversation
EncodedS2ShapeIndex::Init returns true without decoding the cells, so a malformed encoding is not discovered until the cell is reached. The header said nothing about this, which leaves a reader unable to tell an out-of- contract input from an unhandled one. Document it where the other encoded types do: Init assumes a trusted byte stream, and reading a malformed one through the unchecked accessors is outside the contract. Named the actual failure mode, since it is not a clean error -- S2ShapeIndexCell::Decode() returning false leaves GetCell() null and Iterator::cell() dereferences it without a check.
This was referenced Oct 5, 2026
This branch has not been deployed
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.
Documents the assumption raised in #674, rather than changing behaviour.
EncodedS2ShapeIndex::Initreturnstrueafter reading only what it needs to begin decoding, so a malformed encoding is not discovered until the cell holding it is reached. The header said nothing about that, which leaves a reader unable to tell an out-of-contract input from an unhandled one — which is the reason #674, #676, #677, #678 and #679 all read as bugs againstInitwhen the real issue is the contract it operates under.The wording follows
encoded_s2point_vector.h, which already documents this for its ownInit:Applied to this class, and with the failure mode named, because it is not a clean error. Verified in the tree rather than inferred from the reports:
encoded_s2shape_index.cc:79—if (!cell->Decode(num_shape_ids(), &decoder)) { return nullptr; }encoded_s2shape_index.h:328—Iterator::cell()isreturn *index_->GetCell(cell_pos_);with onlyABSL_DCHECK(!done())So a cell that fails to decode leaves
GetCell()null andIterator::cell()dereferences it. The note says so plainly, and says what a caller must do instead — validate the stream beforeInit(). It does not add a runtime check, and it does not change the return contract ofInit().Comment-only: 12 lines added to one file, no code touched.