Skip to content

Commit

Permalink
refactor(core): Validate Variant ArrayLength against its ArrayDimensi…
Browse files Browse the repository at this point in the history
…ons during binary decode

This lead to the fuzzer complaing since we hade the check for _encode
but not for _decode. This is not a direct memory issue per se. But the
consistency check allows early discovery of problematic values and
can potentially remove bugs where the user relies on the array
dimensions and the array length to match.
  • Loading branch information
jpfr committed Oct 22, 2024
1 parent 740a449 commit 1d1758a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ua_types_encoding_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,18 @@ DECODE_BINARY(Variant) {
}

/* Decode array dimensions */
if(isArray && (encodingByte & (u8)UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS) > 0)
if(isArray && (encodingByte & (u8)UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS) > 0) {
ret |= Array_decodeBinary((void**)&dst->arrayDimensions, &dst->arrayDimensionsSize,
&UA_TYPES[UA_TYPES_INT32], ctx);
/* Validate array length against array dimensions */
size_t totalSize = 1;
for(size_t i = 0; i < dst->arrayDimensionsSize; ++i) {
if(dst->arrayDimensions[i] == 0)
return UA_STATUSCODE_BADDECODINGERROR;
totalSize *= dst->arrayDimensions[i];
}
UA_CHECK(totalSize == dst->arrayLength, ret = UA_STATUSCODE_BADDECODINGERROR);
}

ctx->depth--;
return ret;
Expand Down

0 comments on commit 1d1758a

Please sign in to comment.