Repository navigation
Conversation
Contributor
|
Thank you for taking the time to create this PR and providing so much detail. This PR will be tracked in NODE-7642 and the team will prioritize it in the next triage session. |
4 of 5 tasks
Binary.toExtendedJSON base64-encoded the entire backing buffer instead of the content region [0, position). A Binary built incrementally via put()/write() (whose backing buffer is larger than its content, as documented on the position field) therefore serialized trailing allocator bytes through EJSON.stringify, corrupting the value and breaking EJSON round-trips. This aligns toExtendedJSON with value(), toJSON(), toString() and inspect(), which all slice to position.
spokodev
force-pushed
the
w32/bson-binary-ejson-position
branch
from
October 5, 2026 19:15
445a564 to
63718c6
Compare
Contributor
Author
|
@tadjik1, #908 was approved on 5 October; here is where its two siblings stand. This one is now rebased onto #911 (NODE-7661) is already current with Both will need evergreen authorized on their current heads. |
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.
Description
Binary.toExtendedJSON()base64-encodes the entire backing buffer instead of the written region[0, position), corrupting Extended JSON output for anyBinarybuilt incrementally with the documentedput()/write()API.new Binary()allocates a 256-byte buffer and tracks how much is used inposition. Every other accessor (value(),toJSON(),toString(),inspect()) slices toposition, buttoExtendedJSON()encodedthis.bufferin full. So aBinarywith 3 bytes written serialized to a 344-character base64 string of mostly zero padding instead of the 4 characters for those 3 bytes.The BSON path already slices correctly, so BSON and Extended JSON representations of the same object disagreed. This violates MongoDB Extended JSON v2, where
$binary.base64is the payload, not the internal allocation.Fix
Matches what
value()/toJSON()/toString()already do.Test
Added a
toExtendedJSON()case totest/node/binary.test.ts(mirrors the existingtoString/toJSON"should respect position" tests). It fails before the change (full-buffer base64) and passes after. The full node suite stays green.