MapBufferBuilder: fix size_t→int32 partial-write in putString/putMapBuffer length encoding#56525
Closed
meta-yaohway wants to merge 1 commit intofacebook:mainfrom
Closed
MapBufferBuilder: fix size_t→int32 partial-write in putString/putMapBuffer length encoding#56525meta-yaohway wants to merge 1 commit intofacebook:mainfrom
meta-yaohway wants to merge 1 commit intofacebook:mainfrom
Conversation
…uffer length encoding Summary: The MapBuffer wire format encodes lengths and offsets as `int32_t` (`MapBuffer::getString` / `getMapBuffer` read them as `*reinterpret_cast<const int32_t*>(...)`). But in `putString` and `putMapBuffer`: ```cpp auto strSize = value.size(); // size_t — 8 bytes on 64-bit memcpy(dynamicData_.data() + offset, &strSize, INT_SIZE); // copies first 4 of 8 bytes ``` `auto` deduces `size_t` from `.size()`, and `memcpy(&size_t_var, ..., 4)` writes only the **first 4 bytes** of an 8-byte object: - **little-endian:** writes the low 4 bytes — silent truncation if size > UINT32_MAX - **big-endian:** writes the high 4 bytes — encodes **zero** for normal sizes, producing a corrupt buffer the reader then trusts `putMapBufferList` already had the correct pattern: `auto offset = static_cast<int32_t>(dynamicData_.size())`. This diff applies that same explicit `static_cast<int32_t>` to `putString` (`strSize`, `offset`) and `putMapBuffer` (`mapBufferSize`, `offset`) so the value being `memcpy`'d is exactly `INT_SIZE` bytes wide. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D100376322
|
@meta-yaohway has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100376322. |
Collaborator
|
This pull request was successfully merged by @meta-yaohway in b111c0e When will my fix make it into a release? | How to file a pick request? |
|
This pull request has been merged in b111c0e. |
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.
Summary:
The MapBuffer wire format encodes lengths and offsets as
int32_t(MapBuffer::getString/getMapBufferread them as*reinterpret_cast<const int32_t*>(...)). But inputStringandputMapBuffer:autodeducessize_tfrom.size(), andmemcpy(&size_t_var, ..., 4)writes only the first 4 bytes of an 8-byte object:putMapBufferListalready had the correct pattern:auto offset = static_cast<int32_t>(dynamicData_.size()). This diff applies that same explicitstatic_cast<int32_t>toputString(strSize,offset) andputMapBuffer(mapBufferSize,offset) so the value beingmemcpy'd is exactlyINT_SIZEbytes wide.Changelog: [Internal]
Reviewed By: NickGerleman
Differential Revision: D100376322