pErrCode not set in ACN decoder for OCTET STRING with external size
rphh opened this issue · comments
ASN file:
TEST-DATAVIEW DEFINITIONS ::=
BEGIN
MyInteger ::= INTEGER (0..10)
MyData ::= OCTET STRING (SIZE(0..4))
MyPacket ::= SEQUENCE {
bytes MyData
}
END
ACN file:
TEST-DATAVIEW DEFINITIONS ::= BEGIN
MyData []
MyPacket [] {
len MyInteger [size 8, encoding pos-int],
bytes [size len]
}
END
Asn1scc is invoked using command line:
asn1scc -c --type-prefix asn1Scc -ACN test.asn test.acn
Revelant content of generated test.c
file (some comments added manually):
flag asn1SccMyPacket_ACN_Decode(asn1SccMyPacket* pVal, BitStream* pBitStrm, int* pErrCode)
{
flag ret = TRUE;
*pErrCode = 0;
asn1SccUint MyPacket_len;
/*Decode MyPacket_len */
ret = Acn_Dec_Int_PositiveInteger_ConstSize_8(pBitStrm, (&(MyPacket_len)));
*pErrCode = ret ? 0 : ERR_ACN_DECODE_MYPACKET_LEN;
if (ret) {
/*Decode bytes */
ret = ((MyPacket_len<=4)); // pErrCode is not set here, example: MyPacket_len is 8
if (ret) {
pVal->bytes.nCount = (int)MyPacket_len;
ret = BitStream_DecodeOctetString_no_length(pBitStrm, pVal->bytes.arr, pVal->bytes.nCount);
// pErrCode is not set here, example: MyPacket_len is 4 and bit stream has only 2 bytes left
}
} /*COVERAGE_IGNORE*/
return ret && asn1SccMyPacket_IsConstraintValid(pVal, pErrCode);
}
The issue:
- The error code is not set when decoded length is outside allowed range, in the example the length can be from 0 to 4, what is validated, but when it is invalid, the error code is not set. See the line with comment
pErrCode is not set here, example: MyPacket_len is 8
- The error code is not set when bit stream contains too few bytes than expected, i.e. the total bit stream is 3 octets and the first octet contains length with value 4 (which is valid), then decoder expects 4 more octets, but only two are available. In such case decoder fails, but no error code is set. See the line above comment
pErrCode is not set here, example: MyPacket_len is 4 and bit stream has only 2 bytes left
Expected behaviour:
In both cases the error code shall be set to non zero value.
fixed