mouse07410 / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
101 stars 73 forks source link

CHOICE_decode_aper result was wrong when decoding an extension CHOICE #126

Closed tangzhikun closed 1 year ago

tangzhikun commented 1 year ago

I am decoding an extension CHOICE, but the CHOICE_decode_aper result was wrong. The result was corrected after that changes made.

-if (ct && ct->upper_bound >= ct->lower_bound) {
-value = aper_get_nsnnwn(pd, ct->upper_bound - ct->lower_bound + 1);
+value = uper_get_nsnnwn(pd);
if(value < 0) ASN__DECODE_STARVED;
value += specs->ext_start;
if((unsigned)value >= td->elements_count)
    ASN__DECODE_FAILED;
-}

I'm an asn noob, it is the right way to fix it? or can you tell me how to fix it?

mouse07410 commented 1 year ago

is this the right way to fix it?

Offhand, no it isn't - because a) you're presumably decoding an APER PDU, but you're switching to UPER decoder for pd; and b) the code was supposed to validate and ensure that the value falls within the defined range (resides between ct->lower_bound and ct->upper_bound). You merely disposed of all those checks - this does not look good.

What is the value (original, and decoded in both cases), and what does its encoding look like? Also, what happens if you try to decode that PDU on OSS Nokalva ASN.1 playground?

mouse07410 commented 1 year ago

Closing by #127