Skip to content

Generated C OER decoder fails to decode fixed-length sequences with lengths of more than 255 #160

@multiplemonomials

Description

@multiplemonomials

We have been doing some testing with asn1tools, and ran into an odd bug. It appears that if you define a SEQUENCE OF field which is fixed length and greater than 255, the generated OER C decoder cannot decode the field. Example:

MyMessage SEQUENCE ::= {
    someArray SEQUENCE (SIZE(512)) OF Int8
}

If I generate an oer decoder for that, the C code ends up with something like this:

    number_of_length_bytes_1 = decoder_read_uint8(decoder_p);
    length = decoder_read_uint8(decoder_p);

    if ((number_of_length_bytes_1 != 1u) || (length > 0u)) {
        decoder_abort(decoder_p, EBADLENGTH);

        return;
    }

Since the size of the sequence, 512, does not fit in one byte, number_of_length_bytes_1 ends up as 2. So, decoding fails.

I apologize if I've just missed something and this is expected behavior, but it seems like a potential issue (especially since the encoder doesn't complain about the length at all). So, I figured I'd report it. For the time being, we worked around the issue by using variable length sequences (e.g. someArray SEQUENCE (SIZE(0..512)) OF Int8), which do not seem to have this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions