[erlang-bugs] Erlang ASN.1 REAL value 0.0 decoding bug

Lev Walkin <>
Sun Jun 26 01:31:15 CEST 2011


I discovered that the asn1ct code mishandles the REAL values.

Here's a simple test case demonstrating inconsistency and mishandling of 0.0 floating point value.

Consider the following ASN.1 module:

	    Real ::= REAL
	    RealWrapper ::= SEQUENCE {
	        real REAL

Running it through the asn1c to decode the 0.0 value encoded as NR3 and as X.690(07/2002)#8.5.2 (If the real value is the value zero, there shall be no contents octets in the encoding.)

1> asn1ct:compile('RealTest', []).
2> asn1ct:decode('RealTest', 'Real', [9,6,3,48,46,69,43,48]).
3> asn1ct:decode('RealTest', 'Real', [9,0]).
% Until now everything is more or less OK.
4> asn1ct:decode('RealTest', 'RealWrapper', [48,8, 9,6,3,48,46,69,43,48]).
% Here comes the trouble:
6> asn1ct:decode('RealTest', 'RealWrapper', [48,2, 9,0]).

This example shows that the same encoding of the REAL value carrying value zero (0.0) results in a proper decoding when attempting to decode it through a typereference Real, yet generates an error when encoded as a field of a container (SEQUENCE, SET, etc).

What should one expect? The consistent result is that line 6 should return {ok, {'RealWrapper', 0}}, which it doesn't.

Please advise.

Lev Walkin

More information about the erlang-bugs mailing list