Repository navigation
Conversation
…nsion upb_Message_ConvertExtension() previously only checked upb_MiniTableField_IsClosedEnum(dst_f), so converting a repeated closed-enum extension or unknown aux field to a repeated open-enum field or extension shallow-copied the source upb_Array*. When the source also carries unknown wire values for that field, decoding unknowns into dst mutates the const source array and reallocates its backing buffer onto dst's arena, causing a heap-use-after-free once dst's arena is freed. Use upb_Converter_NeedsClosedEnumDeepConvert(dst_f, src_f), matching upb_Message_ConvertField().
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.
Summary
upb_Message_ConvertExtension()shallow-copies a repeated closed-enumupb_Array*directly intodstwhen converting to a repeated open-enum field or extension. Whensrcalso carries unknown wire values for that field (the normal result ofupb_Decode()encountering unknown enum values on a closed-enum field), the subsequent unknown-field decoding pass inupb_Message_ConvertInternal()appends those values directly intosrc's sharedupb_Arrayusingdst's arena.This:
const upb_Message* srcin place, appending invalid closed-enum values intosrc.src's array buffer ontodst's arena (c->arena), causing a heap-use-after-free whensrcis read afterdst's arena is freed.upb_Message_IsEqual(decoded_msg, dst, dst_mt, 0)) inupb_Message_Convert().Root Cause
For regular base fields,
upb_Converter_NeedsClosedEnumDeepConvert()(upb/message/convert.c:563-582) explicitly deep-copies repeated arrays forClosed -> Openconversions so decoding unknowns intodstcannot mutatesrc's array.However,
upb_Message_ConvertExtension()(upb/message/convert.c:784) only checkedupb_MiniTableField_IsClosedEnum(dst_f), missingClosed -> Openconversions for both canonical repeated closed-enum extensions and demoted non-extension unknownupb_AuxFieldentries.Fix
Use
upb_Converter_NeedsClosedEnumDeepConvert(dst_f, src_f)inupb_Message_ConvertExtension()so repeatedClosed -> Openenum arrays are deep-copied ontodst's arena instead of aliasingsrc's array.Verification
[1, 1, 1, 1]+ unknown values[99..95]onarena_a) converted to a repeated open-enum field onarena_b, followed byupb_Arena_Free(arena_b)and readingsrc, triggersAddressSanitizer: heap-use-after-free(READ of size 4inupb_Array_Get).Proto2EnumMessage->EmptyMessage->TestAllTypesProto3viaAuxFieldfailsUPB_ASSERT(upb_Message_IsEqual(decoded_msg, dst, dst_mt, 0))in Debug and triggers the same cross-arena heap-use-after-free in-DNDEBUGASan builds.upb/message/convert.ccompiles cleanly with-Wall -Wextra -Werror.AuxFieldrepros pass cleanly under Debug+ASan+UBSan, Release+ASan+UBSan (-DNDEBUG), Release (-O2 -DNDEBUG), and FastTable Release (-O2 -DNDEBUG -DUPB_ENABLE_FASTTABLE=1), leavingsrccompletely unmodified after freeingdst's arena.ConvertTest.ClosedToOpenRepeatedEnumAuxFieldDoesNotMutateSourceinupb/message/convert_test.cc.