fix(NODE-7661): count empty-scope Code as code_with_scope in calculateObjectSize - #911
Open
spokodev wants to merge 1 commit into
Open
fix(NODE-7661): count empty-scope Code as code_with_scope in calculateObjectSize#911spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
A Code value with a present but empty scope object serializes as the BSON code_with_scope (0x0f) type, but calculateObjectSize gated the code_with_scope branch on the scope having at least one key. As a result calculateObjectSize under-reported such documents by 9 bytes versus the bytes serialize actually writes. Match the serializer, which emits code_with_scope whenever scope is a non-null object, so the two agree for empty scopes.
Contributor
|
Thanks for your contribution! NODE-7661 will track this request and it will be picked up in the next triage session. |
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.
calculateObjectSizedisagrees withserializefor aCodewhose scope is a present but empty object.The serializer emits
code_with_scope(0x0f) wheneverscopeis a non-null object, including{}.calculateObjectSizeinstead required the scope to have at least one key before counting thecode_with_scopelayout, so it fell back to the plaincode(0x0d) size and under-reported by 9 bytes (the 4-byte total-size field plus the 5-byte empty scope subdocument).Gate the
code_with_scopesize branch onscopebeing a non-null object, matching the serializer; the size-calculation stack already accounts for the empty scope subdocument. Adds a regression test assertingcalculateObjectSize === serialize().byteLengthfor an empty-scopeCode.