Skip to content

Commit 95129b8

Browse files
Parser: let cbor_value_leave_container() consume the Break
Instead of consuming it at the end of the last element of a map or array of unknown length. This allows us to obtain the pointer to or offset of the Break byte. Signed-off-by: Thiago Macieira <[email protected]>
1 parent d503c11 commit 95129b8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/cborparser.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ static CborError preparse_next_value_nodecrement(CborValue *it)
268268
/* but we weren't expecting it! */
269269
return CborErrorUnexpectedBreak;
270270
}
271-
advance_bytes(it, 1);
272271
it->type = CborInvalidType;
273272
it->remaining = 0;
273+
it->flags |= CborIteratorFlag_UnknownLength; /* leave_container must consume the Break */
274274
return CborNoError;
275275
}
276276

@@ -286,6 +286,7 @@ static CborError preparse_next_value(CborValue *it)
286286
if (it->remaining != UINT32_MAX) {
287287
if (itemCounts && --it->remaining == 0) {
288288
it->type = CborInvalidType;
289+
it->flags &= ~CborIteratorFlag_UnknownLength; /* no Break to consume */
289290
return CborNoError;
290291
}
291292
}
@@ -604,7 +605,10 @@ CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed)
604605
{
605606
cbor_assert(cbor_value_is_container(it));
606607
cbor_assert(recursed->type == CborInvalidType);
608+
607609
copy_current_position(it, recursed);
610+
if (recursed->flags & CborIteratorFlag_UnknownLength)
611+
advance_bytes(it, 1);
608612
return preparse_next_value(it);
609613
}
610614

0 commit comments

Comments
 (0)