Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
multiplemonomials opened this issue Feb 22, 2023 · 0 comments

Comments

@multiplemonomials
Copy link

multiplemonomials commented Feb 22, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant