zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Range check for dynamic field length

Open mikir opened this issue 4 years ago • 1 comments

There is no range check for dynamic field length during runtime. Example:

struct Container
{
    uint64      length;
    bit<length> unsignedBitField;
    int<length> signedBitField;
};

It would be nice to have runtime range check that length is not bigger than 64. Currently, this issue is reported only during writing without any specification of problematic field.

mikir avatar Jun 10 '20 09:06 mikir

Note that with -withRangeCheckCode the check for maximum numbits is done (see BitFieldUtil.cpp, bitfield.py, Util.java. It's only missing in Java for unsigned bitfields which are mapped to BigInteger. However it's only a part of range check, which primary task is to check the range of the stored value, not the number of bits. The length should be checked even -withoutRangeCheckCode. Currently in Java it's possible to write/read dynamic unsigned bitfield with length > 64bits.

Mi-La avatar Jun 12 '20 19:06 Mi-La