QCBORDecode_GetNext() returns a QCBOR_ERR_STRING_ALLOCATE error.
Bug seems to be in QCBORDecode_GetNextFullString() in file qcbor_decode.c at line 1310:
/* The first time throurgh FullString.ptr is NULL and this is
* equivalent to StringAllocator_Allocate(). Subsequently it is
* not NULL and a reallocation happens.
*/
UsefulBuf NewMem = StringAllocator_Reallocate(pAllocator,
FullString.ptr,
FullString.len + StringChunkItem.val.string.len);
if(UsefulBuf_IsNULL(NewMem)) {
uReturn = QCBOR_ERR_STRING_ALLOCATE;
break;
}
As this is the first chunk, FullString.ptr is nil and FullString.len is 0. Since StringChunkItem.val.string.len is also 0, the allocator is called with a nil pOldMem and a uNewSize of 0. The allocator then returns NULLUsefulBuf which is interpreted as an error.
When decoding the following CBOR:
QCBORDecode_GetNext()
returns a QCBOR_ERR_STRING_ALLOCATE error.Bug seems to be in
QCBORDecode_GetNextFullString()
in file qcbor_decode.c at line 1310:As this is the first chunk,
FullString.ptr
is nil andFullString.len
is 0. SinceStringChunkItem.val.string.len
is also 0, the allocator is called with a nil pOldMem and a uNewSize of 0. The allocator then returns NULLUsefulBuf which is interpreted as an error.Test Code