fix: add bounds check before memcpy in decoder.h - #28805
Open
anupamme wants to merge 3 commits into
Open
Conversation
Automated security fix generated by OrbisAI Security
shaod2
self-requested a review
July 27, 2026 15:32
Member
|
Thanks for the contribution. Is it possible to create a test case for the change? |
anupamme
added a commit
to anupamme/protobuf
that referenced
this pull request
Jul 29, 2026
This test validates the security fix in commit 2027f1f that prevents zero-size malloc calls when decoding empty string fields. The fix adds a guard `&& tmp.size > 0` in _upb_Decoder_ReadString to skip malloc(0) calls, which have implementation-defined behavior and can return NULL on some systems. The test specifically covers: - Decoding empty string fields without kUpb_DecodeOption_AliasString (the vulnerable code path that would attempt malloc(0)) - Verifying decode succeeds without errors - Confirming the field is correctly set to an empty string - Testing both fast-table and non-fast-table decode paths - Comparing with alias mode for completeness Addresses review comment on PR protocolbuffers#28805. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Author
added. pls review. |
shaod2
requested review from
ericsalo and
haberman
and removed request for
shaod2
July 29, 2026 15:03
Member
|
Thanks! Could you also sign CLA plz? |
This test validates the security fix in commit 2027f1f that prevents zero-size malloc calls when decoding empty string fields. The fix adds a guard `&& tmp.size > 0` in _upb_Decoder_ReadString to skip malloc(0) calls, which have implementation-defined behavior and can return NULL on some systems. The test specifically covers: - Decoding empty string fields without kUpb_DecodeOption_AliasString (the vulnerable code path that would attempt malloc(0)) - Verifying decode succeeds without errors - Confirming the field is correctly set to an empty string - Testing both fast-table and non-fast-table decode paths - Comparing with alias mode for completeness Addresses review comment on PR protocolbuffers#28805.
anupamme
force-pushed
the
fix-repo-protobuf-decoder-zero-size-malloc-guard
branch
from
July 29, 2026 15:51
970f612 to
49e600e
Compare
Author
done. |
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
Fix critical severity security issue in
upb/wire/internal/decoder.h.Vulnerability
V-001upb/wire/internal/decoder.h:256Description: The upb_Arena_Realloc function performs memcpy without validating that 'ptr' points to a buffer of at least 'oldsize' bytes. While UPB_MIN provides some protection, if 'oldsize' exceeds the actual allocated size of 'ptr', this reads beyond buffer boundaries.
Evidence
Scanner confirmation: multi_agent_ai rule
V-001flagged this pattern.Production code: This file is in the production codebase, not test-only code.
Threat Model Context
This appears to be an internal/admin endpoint with restricted access. This is a local CLI tool - exploitation requires the attacker to control command-line arguments or input files.
Changes
upb/wire/internal/decoder.hBehavior Preservation
The change is scoped to 1 file on the vulnerable path, and the project's existing tests still pass, so intended behavior is unchanged.
Verification
Security Invariant
Regression test
This test guards against regressions — it's useful independent of the code change above.
Automated security fix by OrbisAI Security