Increase allowed nesting level to 15
diff --git a/Makefile b/Makefile
index b7d940c..15a2c17 100644
--- a/Makefile
+++ b/Makefile
@@ -57,7 +57,7 @@
test/half_to_double_from_rfc7049.o: test/half_to_double_from_rfc7049.h
test/qcbor_decode_malloc_test.o: test/qcbor_decode_malloc_tests.h
-cmd_line_main.o: test/run_tests.h
+cmd_line_main.o: test/run_tests.h inc/qcbor.h
min_use_main.o: inc/qcbor.h inc/UsefulBuf.h
diff --git a/cmd_line_main.c b/cmd_line_main.c
index d1ab0ae..7218e76 100644
--- a/cmd_line_main.c
+++ b/cmd_line_main.c
@@ -50,6 +50,7 @@
// Type and size of return from sizeof() varies. These will never be large so cast is safe
// TODO: use fputs_wrapper to output these
+ printf("sizeof(QCBORTrackNesting) %d\n", (uint32_t)sizeof(QCBORTrackNesting));
printf("sizeof(QCBOREncodeContext) %d\n", (uint32_t)sizeof(QCBOREncodeContext));
printf("sizeof(QCBORDecodeContext) %d\n", (uint32_t)sizeof(QCBORDecodeContext));
printf("sizeof(QCBORDecodeNesting) %d\n", (uint32_t)sizeof(QCBORDecodeNesting));
diff --git a/inc/qcbor.h b/inc/qcbor.h
index 4c32bca..dad939a 100644
--- a/inc/qcbor.h
+++ b/inc/qcbor.h
@@ -78,7 +78,7 @@
that is public. This is done this way so there can be a nice
separation of public and private parts in this file.
*/
-#define QCBOR_MAX_ARRAY_NESTING1 10 // Do not increase this over 255
+#define QCBOR_MAX_ARRAY_NESTING1 15 // Do not increase this over 255
/*
@@ -91,8 +91,9 @@
struct down so it can be on the stack without any concern. It would be about
double if size_t was used instead.
- 64-bit machine: 10 * (4 + 2 + 1 + 1) + 8 = 88 bytes
- 32-bit machine: 10 * (4 + 2 + 1 + 1) + 4 = 84 bytes
+ Size approximation (varies with CPU/compiler):
+ 64-bit machine: (15 + 1) * (4 + 2 + 1 + 1 pad) + 8 = 136 bytes
+ 32-bit machine: (15 + 1) * (4 + 2 + 1 + 1 pad) + 4 = 132 bytes
*/
typedef struct __QCBORTrackNesting {
// PRIVATE DATA STRUCTURE
@@ -112,8 +113,9 @@
Context / data object for encoding some CBOR. Used by all encode functions to
form a public "object" that does the job of encdoing.
- 64-bit machine: 27 + 1 (+ 4 padding) + 88 = 32+88 = 120 bytes
- 32-bit machine: 15 + 1 + 84 = 90 bytes
+ Size approximation (varies with CPU/compiler):
+ 64-bit machine: 27 + 1 (+ 4 padding) + 136 = 32 + 136 = 168 bytes
+ 32-bit machine: 15 + 1 + 132 = 148 bytes
*/
struct _QCBOREncodeContext {
// PRIVATE DATA STRUCTURE
@@ -131,8 +133,8 @@
for arrays and maps.
Size approximation (varies with CPU/compiler):
- 64-bit machine: 4 * 10 + 8 + 4 padding = 56
- 32-bit machine: 4 * 10 + 4 = 44
+ 64-bit machine: 4 * 16 + 8 = 72
+ 32-bit machine: 4 * 16 + 4 = 68
*/
typedef struct __QCBORDecodeNesting {
// PRIVATE DATA STRUCTURE
@@ -151,8 +153,8 @@
functions form an "object" that does CBOR decoding.
Size approximation (varies with CPU/compiler):
- 64-bit machine: 32 + 1 + 1 + 6 bytes padding + 56 + 8 = 104 bytes
- 32-bit machine: 16 + 1 + 1 + 2 bytes padding + 44 + 4 = 68 bytes
+ 64-bit machine: 32 + 1 + 1 + 6 bytes padding + 72 + 16 = 128 bytes
+ 32-bit machine: 16 + 1 + 1 + 2 bytes padding + 68 + 8 = 68 bytes
*/
struct _QCBORDecodeContext {
// PRIVATE DATA STRUCTURE
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 86c62bb..12be915 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -611,8 +611,11 @@
return(nReturn);
}
-
-static uint8_t spTooDeepArrays[] = {0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x80};
+// Big enough to test nesting to the depth of 24
+static uint8_t spTooDeepArrays[] = {0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+ 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+ 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
+ 0x80};
int ParseTooDeepArrayTest()
{
@@ -624,7 +627,7 @@
QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(spTooDeepArrays), QCBOR_DECODE_MODE_NORMAL);
- for(i = 0; i < 10; i++) {
+ for(i = 0; i < QCBOR_MAX_ARRAY_NESTING1; i++) {
if(QCBORDecode_GetNext(&DCtx, &Item) != 0 ||
Item.uDataType != QCBOR_TYPE_ARRAY ||
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index b42002e..395e43a 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -1637,26 +1637,28 @@
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
// ---- Make a complicated nested CBOR structure ---
- QCBOREncode_OpenArray(&EC);
+#define BSTR_TEST_DEPTH 10
- for(int i = 0; i < QCBOR_MAX_ARRAY_NESTING-2; i++) {
+ QCBOREncode_OpenArray(&EC);
+
+ for(int i = 0; i < BSTR_TEST_DEPTH-2; i++) {
QCBOREncode_BstrWrap(&EC);
QCBOREncode_AddUInt64(&EC, i);
}
- for(int i = 0; i < QCBOR_MAX_ARRAY_NESTING-2; i++) {
+ for(int i = 0; i < BSTR_TEST_DEPTH-2; i++) {
QCBOREncode_CloseBstrWrap(&EC, NULL);
QCBOREncode_AddUInt64(&EC, i);
}
- for(int i = 0; i < (QCBOR_MAX_ARRAY_NESTING-2)/3; i++) {
+ for(int i = 0; i < (BSTR_TEST_DEPTH-2)/3; i++) {
QCBOREncode_OpenMap(&EC);
QCBOREncode_BstrWrapMapN(&EC, i+0x20);
QCBOREncode_OpenArray(&EC);
QCBOREncode_AddUInt64(&EC, i+0x10);
}
- for(int i = 0; i < (QCBOR_MAX_ARRAY_NESTING-2)/3; i++) {
+ for(int i = 0; i < (BSTR_TEST_DEPTH-2)/3; i++) {
QCBOREncode_CloseArray(&EC);
QCBOREncode_AddUInt64(&EC, i+0x30);
QCBOREncode_CloseBstrWrap(&EC, NULL);