From 3c10e6fa71cbee85c540c0702a5a95333cd3be32 Mon Sep 17 00:00:00 2001 From: Kent Ryhorchuk Date: Mon, 15 Jul 2013 18:04:47 -0700 Subject: [PATCH] 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. --- pb_decode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pb_decode.c b/pb_decode.c index c5336981..a079556e 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -308,12 +308,12 @@ static bool pb_field_next(pb_field_iterator_t *iter) prev_size *= iter->pos->array_size; } - if (PB_HTYPE(iter->pos->type) == PB_HTYPE_REQUIRED) - iter->required_field_index++; - if (iter->pos->tag == 0) return false; /* Only happens with empty message types */ + if (PB_HTYPE(iter->pos->type) == PB_HTYPE_REQUIRED) + iter->required_field_index++; + iter->pos++; iter->field_index++; if (iter->pos->tag == 0) -- 2.16.6