Repository navigation
Conversation
upb_Message_Convert() did not handle unlinked destination submessage fields (upb_MiniTable_SubMessage(dst_f) == NULL), causing NULL pointer dereferences or corrupted destination messages that crash upb_Encode(): - Scalar submessages called upb_Message_GetOrCreateMutableMessage() with a NULL sub-MiniTable (assert in debug, SIGSEGV in release). - Repeated submessages fell through to the primitive branch of upb_Array_DeepConvert(), copying source pointers into an unlinked destination array. - Map fields with unlinked value submessages copied source submessage pointers into dst_map instead of encoding entries as unknown fields. - Extensions and unknown aux fields targeting unlinked destination fields called upb_Message_New(NULL) for scalars or populated unlinked arrays for repeated fields. Preserve non-empty unlinked submessages as unknown aux fields (or encoded unknown bytes for maps), matching upb_Decode() semantics, and fail cleanly with kUpb_ConvertStatus_Incompatible on invalid unlinked source fields or unlinked registered destination extensions.
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_Convert()does not handle unlinked submessage fields (upb_MiniTable_SubMessage(dst_f) == NULL) on the destinationupb_MiniTable, which occur legitimately in tree-shaken or dynamically built MiniTables. Whileupb_Decode()preserves unlinked submessage fields (and map fields whose value submessage is unlinked) as unknown fields (_upb_Decoder_CheckUnlinked,DecodeDynamicMapUnlinkedValue),upb_Message_Convert()crashes with NULL pointer dereferences or produces corrupted messages that crashupb_Encode():upb_Message_ConvertField): callsupb_Message_GetOrCreateMutableMessage()withdst_sub_mt == NULL-> debugUPB_ASSERT(sub_mini_table)failure and releaseSIGSEGV.upb_Message_ConvertArrayField/upb_Array_DeepConvert): falls through to the primitiveelsebranch inupb_Array_DeepConvert(), copying source submessage pointers into an unlinked destination array -> debug round-trip assertion failure andSIGSEGVinupb_Encode().upb_Message_ConvertMapField/upb_Map_DeepConvert*): bothint-key andstring-key maps copy raw source submessage pointers intodst_mapwhiledst_val_mt == NULL-> debug round-trip assertion failure andSIGSEGVinupb_Encode().AuxFieldtargeting an unlinked destination field (upb_Message_ConvertExtension): callsupb_Message_New(NULL, c->arena)for scalars (immediate UBSan NULL deref /SIGSEGV) or populates an unlinked array for repeated fields (SIGSEGVinupb_Encode()).Fix
Align
upb_Message_Convert()withupb_Decode()'s unlinked submessage behavior:dst_sub_mt == NULL): demote non-empty fields to unknown aux fields viaupb_Message_DemoteToAuxField()(skipping empty arrays).dst_val_mt == NULL): encode non-empty maps to unknown wire bytes viaupb_Message_EncodeUnknownField()+upb_Message_FlushUnknownChunk()(skipping empty maps), matchingDecodeDynamicMapUnlinkedValue.dst_sub_mt == NULL): preserve non-empty entries as unknown aux fields via a sharedupb_Message_AddUnknownAuxField()helper.srcsubmessage or unlinked registered destination extension): fail cleanly withkUpb_ConvertStatus_Incompatible(returningNULL).Verification
map<int32, SubMsg>,map<string, SubMsg>,AuxFieldscalar,AuxFieldrepeated) fail debug assertions and crash with ASanSEGV+ UBSan NULL dereference under-DNDEBUG -fsanitize=address,undefined.upb/message/convert.ccompiles cleanly with-Wall -Wextra -Werror.#ifndef NDEBUGround-trip check), Release+ASan+UBSan (-DNDEBUG), Release (-O2 -DNDEBUG), and FastTable Release (-O2 -DNDEBUG -DUPB_ENABLE_FASTTABLE=1).upb/message/convert_test.cc:UnlinkedDestinationScalarSubmessage,UnlinkedDestinationRepeatedSubmessage,UnlinkedDestinationMapValueSubmessage, andUnlinkedDestinationAuxFieldSubmessages.