maxime-esa / asn1scc

ASN1SCC: An open source ASN.1 compiler for embedded systems

Home Page:https://www.thanassis.space/asn1.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PER Real codec does not handle special cases according to standard

fschramka opened this issue · comments

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?):

  • Positive Infinity
  • Negative Infinity
  • Zero
  • Minus Zero (Chapter 8.5.3)
  • Not A Number (Chapter 8.5.9)

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):

void BitStream_EncodeReal(BitStream* pBitStrm, asn1Real v)

Encoding method (Scala backend):
https://github.com/ateleris/asn1scc/blob/d02c9a967fedbac046d18efc7f0b5b4ad5369b61/asn1scala/src/main/scala/asn1scala/asn1jvm_Codec.scala#L418

Decoding method (C backend):

flag BitStream_DecodeReal(BitStream* pBitStrm, asn1Real* v)

Decoding method (Scala backend):
https://github.com/ateleris/asn1scc/blob/d02c9a967fedbac046d18efc7f0b5b4ad5369b61/asn1scala/src/main/scala/asn1scala/asn1jvm_Codec.scala#L510C29-L510C29

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