Repository navigation
Conversation
Passing a NULL symtab to upb_JsonDecode() is supported for messages that do not require extension or Any type resolution (matching upb_JsonEncode(), which explicitly checks `if (!e->ext_pool)` before encoding Any). However, two sites in upb/json/decode.c unconditionally pass d->symtab into upb_DefPool lookup functions: 1. jsondec_field() passes d->symtab to upb_DefPool_FindExtensionByNameWithSize() whenever an input JSON object contains a bracketed key such as `"[foo]"`, causing an immediate NULL-pointer dereference even when upb_JsonDecode_IgnoreUnknown is enabled. 2. jsondec_typeurl() passes d->symtab to upb_DefPool_FindMessageByNameWithSize() when decoding a google.protobuf.Any `@type` URL, causing a NULL-pointer dereference instead of returning an error status. Guard d->symtab at both sites: treat bracketed extension keys as unknown fields when d->symtab is NULL, and return an error message matching upb/json/encode.c when decoding Any without a symtab.
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
Fixes two NULL-pointer dereferences (
SIGSEGV) inupb_JsonDecode()(upb/json/decode.c) triggered by untrusted JSON inputs whensymtabisNULL.Root Cause
Passing
symtab == NULLis supported for decoding messages that do not require extension orgoogle.protobuf.Anyresolution (matchingupb/json/encode.c:370, which explicitly checksif (!e->ext_pool)before encodingAny).However, two call sites in
upb/json/decode.cunconditionally dereferenced->symtab:jsondec_field()(upb/json/decode.c:966-969): Any JSON object with a bracketed key such as{"[foo.bar]": 1}unconditionally callsupb_DefPool_FindExtensionByNameWithSize(d->symtab, ...), crashing withSIGSEGVinsideupb_strtable_lookup2(upb/hash/common.c:133), even whenupb_JsonDecode_IgnoreUnknownis enabled.jsondec_typeurl()(upb/json/decode.c:1433): Decoding agoogle.protobuf.Any@typeURL unconditionally callsupb_DefPool_FindMessageByNameWithSize(d->symtab, ...), crashing withSIGSEGVinstead of returning an error status.Fix
jsondec_field(), guardd->symtabso bracketed extension keys resolve toNULL(handled by the existing unknown-field /IgnoreUnknownpath) whend->symtab == NULL.jsondec_typeurl(), checkif (!d->symtab)and report"Tried to decode Any, but no symtab was provided"(mirroringupb/json/encode.c:371).Testing
JsonTest.NullSymtabExtensionAndAnyinupb/json/decode_test.cccovering bracketed extension keys (default andupb_JsonDecode_IgnoreUnknown) andgoogle.protobuf.Anywithsymtab == nullptr.-DNDEBUG) and Debug builds as well as-std=c99 -Wall -Wextra -Werror.