Autotest: test the error conditions in the parser and the encoder
The encoder only supports two error conditions: out of memory (need more
buffer) and illegal simple types. It's possible for the encoder to
encode an array or map with a size the decoder can't parse (UINT32_MAX),
but that's not an error condition.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
diff --git a/src/cborparser.c b/src/cborparser.c
index b7df8f1..03bb554 100644
--- a/src/cborparser.c
+++ b/src/cborparser.c
@@ -139,7 +139,7 @@
if (descriptor > Value64Bit) {
if (unlikely(descriptor != IndefiniteLength))
- return CborErrorIllegalNumber;
+ return type == CborSimpleType ? CborErrorUnknownType : CborErrorIllegalNumber;
if (likely(!is_fixed_type(type))) {
// special case
it->flags |= CborIteratorFlag_UnknownLength;
@@ -398,12 +398,18 @@
assert(err == CborNoError);
recursed->remaining = len;
- if (recursed->remaining != len || len == UINT32_MAX)
+ if (recursed->remaining != len || len == UINT32_MAX) {
+ // back track the pointer to indicate where the error occurred
+ recursed->ptr = it->ptr;
return CborErrorDataTooLarge;
+ }
if (recursed->type == CborMapType) {
// maps have keys and values, so we need to multiply by 2
- if (recursed->remaining > UINT32_MAX / 2)
+ if (recursed->remaining > UINT32_MAX / 2) {
+ // back track the pointer to indicate where the error occurred
+ recursed->ptr = it->ptr;
return CborErrorDataTooLarge;
+ }
recursed->remaining *= 2;
}
if (len != 0)