esa / asn1scc

ASN1SCC: An open source ASN.1 compiler for embedded systems
https://www.thanassis.space/asn1.html
Other
272 stars 58 forks source link

PER Real codec does not handle special cases according to standard #287

Closed fschramka closed 10 months ago

fschramka commented 11 months ago

The PER Real codec does not handle special cases such as '-0.0' or 'NaN' according to the Rec. ITU-T X.690 (02/2021) standard (get it from here).

Special cases that are implemented (in C, ada?):

If the double value MINUS_ZERO is encoded and decoded, the MINUS is lost in translation. This should not lead to massive problems in reality, but should still be integrated because the standard holds a special case for it.

NaN is not implemented at all in C (and ada?) - hence the exponent and the mantissa get exported from the NaN double / float bitstring. If an PER based decoder reads a stream created by our encoder, it could lead to a crash because the asumption is met that there is no NaN after a certain point.

This was already implemented in the Scala backend - I added all links here :)

Encoding method (C backend): https://github.com/maxime-esa/asn1scc/blob/1ddce9cea6001ffe76b86db144777321385b4203/asn1crt/asn1crt_encoding.c#L1119 Encoding method (Scala backend): https://github.com/ateleris/asn1scc/blob/d02c9a967fedbac046d18efc7f0b5b4ad5369b61/asn1scala/src/main/scala/asn1scala/asn1jvm_Codec.scala#L418

Decoding method (C backend): https://github.com/maxime-esa/asn1scc/blob/1ddce9cea6001ffe76b86db144777321385b4203/asn1crt/asn1crt_encoding.c#L1187 Decoding method (Scala backend): https://github.com/ateleris/asn1scc/blob/d02c9a967fedbac046d18efc7f0b5b4ad5369b61/asn1scala/src/main/scala/asn1scala/asn1jvm_Codec.scala#L510C29-L510C29

usr3-1415 commented 10 months ago

Thank you for bringing this to my attention and for providing the Scala implementation. The issue has been fixed for both C and Ada