Skip to content

Commit

Permalink
Fixed fuzz bug in MiniDescriptor parsing for extensions.
Browse files Browse the repository at this point in the history
If the extension MiniDescriptor did not contain any fields, we would read an uninitialized value.  We need to add a check that the extension descriptor contains exactly one field.

PiperOrigin-RevId: 475075831
  • Loading branch information
haberman authored and copybara-github committed Sep 18, 2022
1 parent 668cebb commit 6795ec1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions upb/mini_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,10 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr,
while (ptr < d->end) {
char ch = *ptr++;
if (ch <= kUpb_EncodedValue_MaxField) {
if (!d->table && last_field) return --ptr;
if (!d->table && last_field) {
// For extensions, consume only a single field and then return.
return --ptr;
}
upb_MiniTable_Field* field = fields;
*field_count += 1;
fields = (char*)fields + field_size;
Expand Down Expand Up @@ -1148,7 +1151,7 @@ const char* upb_MiniTable_BuildExtension(const char* data, size_t len,
uint16_t count = 0;
const char* ret =
upb_MtDecoder_Parse(&decoder, data, len, ext, sizeof(*ext), &count, NULL);
if (!ret) return NULL;
if (!ret || count != 1) return NULL;

upb_MiniTable_Field* f = &ext->field;

Expand Down
5 changes: 5 additions & 0 deletions upb/msg_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,9 @@ TEST(MessageTest, MapField) {
// -696925610, -654590577);
// }
//
// TEST(FuzzTest, ExtendMessageSetWithEmptyExtension) {
// DecodeEncodeArbitrarySchemaAndPayload({{"\n"}, {}, "_", {}}, std::string(), 0,
// 0);
// }
//
// end:google_only

0 comments on commit 6795ec1

Please sign in to comment.