Skip to content

Skip memcpy when source vector is empty in MapBufferBuilder::build#57398

Closed
javache wants to merge 1 commit into
react:mainfrom
javache:export-D110316404
Closed

Skip memcpy when source vector is empty in MapBufferBuilder::build#57398
javache wants to merge 1 commit into
react:mainfrom
javache:export-D110316404

Conversation

@javache

@javache javache commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary:
buckets_.data() and dynamicData_.data() return nullptr when the vector is empty, and glibc marks memcpy's src argument as nonnull. Passing nullptr is UB even with a size of 0, which trips UBSan halt-on-error on any MapBuffer that has no buckets (EMPTY()) or no dynamic-data entries (scalar-only maps). Guard both memcpys with an empty check.

Changelog:
[General][Fixed] - Avoid memcpy(_, nullptr, 0) UB in MapBufferBuilder::build for empty / scalar-only MapBuffers

Reviewed By: cortinico

Differential Revision: D110316404

Summary:
`buckets_.data()` and `dynamicData_.data()` return `nullptr` when the vector is empty, and glibc marks `memcpy`'s src argument as `nonnull`. Passing `nullptr` is UB even with a size of 0, which trips UBSan halt-on-error on any MapBuffer that has no buckets (`EMPTY()`) or no dynamic-data entries (scalar-only maps). Guard both memcpys with an empty check.

Changelog:
[General][Fixed] - Avoid `memcpy(_, nullptr, 0)` UB in `MapBufferBuilder::build` for empty / scalar-only MapBuffers

Reviewed By: cortinico

Differential Revision: D110316404
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 1, 2026
@meta-codesync

meta-codesync Bot commented Jul 1, 2026

Copy link
Copy Markdown

@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110316404.

@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Jul 1, 2026

@cortinico cortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

javache added a commit to javache/react-native that referenced this pull request Jul 1, 2026
…eact#57398)

Summary:

`buckets_.data()` and `dynamicData_.data()` return `nullptr` when the vector is empty, and glibc marks `memcpy`'s src argument as `nonnull`. Passing `nullptr` is UB even with a size of 0, which trips UBSan halt-on-error on any MapBuffer that has no buckets (`EMPTY()`) or no dynamic-data entries (scalar-only maps). Guard both memcpys with an empty check.

Changelog:
[General][Fixed] - Avoid `memcpy(_, nullptr, 0)` UB in `MapBufferBuilder::build` for empty / scalar-only MapBuffers

Reviewed By: cortinico

Differential Revision: D110316404
@meta-codesync meta-codesync Bot closed this in 34ccf4f Jul 1, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Jul 1, 2026
@meta-codesync

meta-codesync Bot commented Jul 1, 2026

Copy link
Copy Markdown

This pull request has been merged in 34ccf4f.

@javache javache deleted the export-D110316404 branch July 1, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants