Skip to content

[codex] Guard upb extension promotion by wire type#28144

Draft
kuranikaran wants to merge 1 commit into
protocolbuffers:mainfrom
kuranikaran:codex/fix-upb-promote-wire-type
Draft

[codex] Guard upb extension promotion by wire type#28144
kuranikaran wants to merge 1 commit into
protocolbuffers:mainfrom
kuranikaran:codex/fix-upb-promote-wire-type

Conversation

@kuranikaran

Copy link
Copy Markdown

Summary

Guard lazy message-extension promotion so a same-number unknown field is only promoted when its stored wire type is length-delimited. This keeps non-delimited unknowns on the existing skip path instead of capturing them and re-decoding them as embedded messages.

Root cause

upb_Message_GetOrPromoteExtension() matched unknown fields by field number only before calling upb_MiniTable_ParseUnknownMessage(). A same-number unknown with a varint or fixed wire type could be interpreted as a length-delimited message payload, causing the varint value bytes to be consumed as a message length.

Tests

  • Added PromoteIgnoresWrongWireType covering ModelExtension1.model_ext encoded with a varint wire type and expecting kUpb_GetExtension_NotPresent.
  • Verified with a standalone clang build using -fsanitize=address,undefined: wrong-wire input returns kUpb_GetExtension_NotPresent; length-delimited empty-message input returns kUpb_GetExtension_Ok with non-null msg_val.

Follow-up

The legacy PromoteUnknownToMessage, PromoteUnknownToMessageArray, and PromoteUnknownToMap paths can reach the same parse helper via FindUnknown; they can receive the same wire-type guard in a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants