tidy up max size in bytes for decoder input and encoder output (#300)
New #define QCBOR_SIZE_MAX that is the same max size for decoder input and encoder output
#define QCBOR_MAX_DECODE_INPUT_SIZE is deprecated
This cleans up a TODO: item for the largest size for encoded output
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/src/decode_nesting.h b/src/decode_nesting.h
index 0e1c3a1..024d228 100644
--- a/src/decode_nesting.h
+++ b/src/decode_nesting.h
@@ -2,7 +2,7 @@
* decode_nesting.c -- All inline implementation of QCBORDecodeNesting
*
* Copyright (c) 2016-2018, The Linux Foundation.
- * Copyright (c) 2018-2024, Laurence Lundblade.
+ * Copyright (c) 2018-2025, Laurence Lundblade.
* Copyright (c) 2021, Arm Limited.
* All rights reserved.
*
@@ -336,12 +336,12 @@
* Have descended into this before this is called. The job here is
* just to mark it in bounded mode.
*
- * Check against QCBOR_MAX_DECODE_INPUT_SIZE make sure that
+ * Check against QCBOR_MAX_SIZE make sure that
* uOffset doesn't collide with QCBOR_NON_BOUNDED_OFFSET.
*
* Cast of uOffset to uint32_t for cases where SIZE_MAX < UINT32_MAX.
*/
- if((uint32_t)uOffset >= QCBOR_MAX_DECODE_INPUT_SIZE) {
+ if((uint32_t)uOffset >= QCBOR_MAX_SIZE) {
return QCBOR_ERR_INPUT_TOO_LARGE;
}
diff --git a/src/qcbor_main_encode.c b/src/qcbor_main_encode.c
index 8da4888..f2f65f4 100644
--- a/src/qcbor_main_encode.c
+++ b/src/qcbor_main_encode.c
@@ -1,6 +1,6 @@
/* ===========================================================================
* Copyright (c) 2016-2018, The Linux Foundation.
- * Copyright (c) 2018-2024, Laurence Lundblade.
+ * Copyright (c) 2018-2025, Laurence Lundblade.
* Copyright (c) 2021, Arm Limited.
* All rights reserved.
*
@@ -644,13 +644,13 @@
*/
size_t uEndPosition = UsefulOutBuf_GetEndPosition(&(pMe->OutBuf));
- /* QCBOR_MAX_ARRAY_OFFSET is slightly less than UINT32_MAX so this
+ /* QCBOR_MAX_SIZE is slightly less than UINT32_MAX so this
* code can run on a 32-bit machine and tests can pass on a 32-bit
* machine. If it was exactly UINT32_MAX, then this code would not
* compile or run on a 32-bit machine and an #ifdef or some machine
- * size detection would be needed reducing portability.
+ * size detection would be needed, reducing portability.
*/
- if(uEndPosition >= QCBOR_MAX_ARRAY_OFFSET) {
+ if(uEndPosition >= QCBOR_MAX_SIZE) {
pMe->uError = QCBOR_ERR_BUFFER_TOO_LARGE;
} else {
diff --git a/src/qcbor_spiffy_decode.c b/src/qcbor_spiffy_decode.c
index 1c13bdc..ba3ff60 100644
--- a/src/qcbor_spiffy_decode.c
+++ b/src/qcbor_spiffy_decode.c
@@ -2,7 +2,7 @@
* qcbor_spiffy_decode.c -- "Spiffy" QCBOR decoding
*
* Copyright (c) 2016-2018, The Linux Foundation.
- * Copyright (c) 2018-2024, Laurence Lundblade.
+ * Copyright (c) 2018-2025, Laurence Lundblade.
* Copyright (c) 2021, Arm Limited.
* All rights reserved.
*
@@ -359,9 +359,9 @@
// Check here makes sure that this won't accidentally be
// QCBOR_MAP_OFFSET_CACHE_INVALID which is larger than
- // QCBOR_MAX_DECODE_INPUT_SIZE.
+ // QCBOR_MAX_SIZE.
// Cast to uint32_t to possibly address cases where SIZE_MAX < UINT32_MAX
- if((uint32_t)uEndOffset >= QCBOR_MAX_DECODE_INPUT_SIZE) {
+ if((uint32_t)uEndOffset >= QCBOR_MAX_SIZE) {
uReturn = QCBOR_ERR_INPUT_TOO_LARGE;
goto Done;
}
diff --git a/src/qcbor_tag_decode.c b/src/qcbor_tag_decode.c
index 2908823..309d4b0 100644
--- a/src/qcbor_tag_decode.c
+++ b/src/qcbor_tag_decode.c
@@ -1,7 +1,7 @@
/* ==========================================================================
* qcbor_tag_decode.c -- Tag content decoders
*
- * Copyright (c) 2024, Laurence Lundblade. All rights reserved.
+ * Copyright (c) 2025, Laurence Lundblade. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -658,14 +658,14 @@
const size_t uPreviousLength = UsefulInputBuf_GetBufferLength(&(pMe->InBuf));
/* This check makes the cast of uPreviousLength to uint32_t below safe. */
- if(uPreviousLength >= QCBOR_MAX_DECODE_INPUT_SIZE) {
+ if(uPreviousLength >= QCBOR_MAX_SIZE) {
uError = QCBOR_ERR_INPUT_TOO_LARGE;
goto Done;
}
const size_t uStartOfBstr = UsefulInputBuf_PointerToOffset(&(pMe->InBuf), pItem->val.string.ptr);
/* This check makes the cast of uStartOfBstr to uint32_t below safe. */
- if(uStartOfBstr == SIZE_MAX || uStartOfBstr > QCBOR_MAX_DECODE_INPUT_SIZE) {
+ if(uStartOfBstr == SIZE_MAX || uStartOfBstr > QCBOR_MAX_SIZE) {
/* This should never happen because pItem->val.string.ptr should
* always be valid since it was just returned.
*/