rdf: fix end pointer guard checking the wrong slice in snippet range parsing - #292
Merged
Merged
Conversation
The guard ahead of endPointerTriples[0] tests len(startPointerTriples) instead, which the previous block has already validated, so it always passes. Its own error message says endPointer, which is what it was meant to check. A range node with a valid startPointer and no endPointer clears every earlier check (3 associated triples, exactly 1 rdf:type, exactly 1 startPointer) if the third triple is some other predicate, and then indexes an empty slice. That panics the parser on malformed RDF input rather than returning the intended error. Same line was wrong in v2_2 and v2_3, so both are fixed here. The existing 0-endPointer test case actually had two endPointers and no startPointer, so it tripped the startPointer guard and never reached this branch. Rewrote it to match what it says it covers. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.
While reading through the RDF snippet parser I noticed the end pointer guard in
setSnippetRangeFromNodechecks the wrong slice:It's pretty much self-evidencing: the error message says
endPointerand formatslen(endPointerTriples), but the condition readsstartPointerTriples, which the block right above has already validated as exactly 1. So the guard can never fire, andendPointerTriples[0]on the next line indexes whatever's there, empty slice or not.To actually reach it you need a range node that clears the earlier checks (exactly 3 associated triples, exactly 1 rdf:type, exactly 1 startPointer) while having no endPointer. A third triple with some other predicate does it:
That panics with
index out of range [0] with length 0instead of returning the error it meant to. Since RDF input is generally untrusted, a malformed document takes down the caller rather than getting a parse error back.The fix is the one-line change to test
endPointerTriples. The same line is wrong in both v2_2 and v2_3, so both are here in one PR.On the test side:
TestCase 4in each file is labelled "triples with 0 endPointer" but it was actually built with two endPointers and zero startPointers, so it tripped the startPointer guard and returned early. That's why the branch never got caught. I rewrote it to be a real 0-endPointer case, which reproduces the panic on main and passes with the fix. TestCase 3 still covers the missing-startPointer path it duplicated.Verified with
go test ./..., all green. Reverting just the two source lines makes the two updated cases panic, so the tests do cover the change.