Check for empty message type before incrementing required_field_index.
If you have a message that defined as empty, but attempt to decode a message that has one or more unknown fields then pb_decode fails. The method used to count the number of required fields counts 1 required field because the default type of PB_LAST_FIELD is PB_HTYPE_REQUIRED.
This commit is contained in:
committed by
Petteri Aimonen
parent
a01856f4ab
commit
3c10e6fa71
@@ -308,12 +308,12 @@ static bool pb_field_next(pb_field_iterator_t *iter)
|
|||||||
prev_size *= iter->pos->array_size;
|
prev_size *= iter->pos->array_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PB_HTYPE(iter->pos->type) == PB_HTYPE_REQUIRED)
|
|
||||||
iter->required_field_index++;
|
|
||||||
|
|
||||||
if (iter->pos->tag == 0)
|
if (iter->pos->tag == 0)
|
||||||
return false; /* Only happens with empty message types */
|
return false; /* Only happens with empty message types */
|
||||||
|
|
||||||
|
if (PB_HTYPE(iter->pos->type) == PB_HTYPE_REQUIRED)
|
||||||
|
iter->required_field_index++;
|
||||||
|
|
||||||
iter->pos++;
|
iter->pos++;
|
||||||
iter->field_index++;
|
iter->field_index++;
|
||||||
if (iter->pos->tag == 0)
|
if (iter->pos->tag == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user