Repository navigation
Start the NOP skip of Advance and AdvanceIter at the NOP - #10
Merged
Merged
Conversation
DeleteElems, SetNull and Deserialize write NOPs. They count the skip of a NOP from the NOP itself. AdvanceInto, PeekNext, NextElementBytes and MarshalJSON read it in the same way. Advance and AdvanceIter counted it from the word after the NOP, and they skipped one word too many. Because of this, ForEach, Interface, FindKey and the helpers of Array lost or misread elements after a NOP. For example, DeleteElems removed 2 from [1,2,3,4], and then Array.ForEach gave only 1. SetNull on the first value of [1.5,2,3] made Advance read the value word of 2 as a tag. Upstream has the same code. A skip of 0 now comes back to the same NOP. Advance cannot return an error, and it goes to the end, as AdvanceInto does. AdvanceIter already returned an error for it. nop_skip_test.go edits documents with DeleteElems and SetNull, also after a round trip through Serialize and Deserialize. It reads them through Advance, AdvanceIter, ForEach, Interface, FindKey and Array.MarshalJSON, and compares each result with encoding/json. MarshalJSON of the document and Object.Map were correct before, and they are the control. Before this change, the test failed on all of the other readers. Four intentional errors in the correction each made a test fail. The references in advance_diff_test.go had the same error, and they get the same correction. In foreach_diff_test.go, the write that replaces a NOP now counts its skip from the NOP too. The common path of each function does not change, because it does not read NOPs.
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.
AdvanceandAdvanceIterskipped one word too many after a NOP. #9 found this error and did not change it. This PR corrects it.The error
DeleteElems,SetNullandDeserializewrite NOPs. They count the skip of a NOP from the NOP itself.AdvanceInto,PeekNext,NextElementBytesandMarshalJSONread it in the same way.AdvanceandAdvanceItercounted it from the word after the NOP.Because of this,
ForEach,Interface,FindKeyand the helpers ofArraylost or misread elements after a NOP:Array.ForEachbefore[1,2,3,4]DeleteElemsremoves2[1][1,3,4][true,false,null,true]DeleteElemsremovesfalse[true,true][true,null,true][1.5,2,3]SetNullon1.52read as a tag[null,2,3]Upstream has the same code.
The change
AdvanceandadvanceIter, the slow path ofAdvanceIter, start the skip at the NOP.Advancecannot return an error, and it goes to the end, asAdvanceIntodoes.AdvanceIteralready returned an error for it.Testing
nop_skip_test.goedits documents withDeleteElemsandSetNull, also after a round trip throughSerializeandDeserialize. It reads each document throughAdvance,AdvanceIter,ForEach,Interface,FindKeyandArray.MarshalJSON. It compares each result withencoding/json.MarshalJSONof the document andObject.Mapwere correct before, and they are the control.advance_diff_test.gohad the same error, and they get the same correction.FuzzParse,FuzzCorrectandFuzzSerializeran for one minute each, with no failure.🤖 Generated with Claude Code