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

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


Hello,

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:

	RealTest DEFINITIONS ::= BEGIN
	    Real ::= REAL
	    RealWrapper ::= SEQUENCE {
	        real REAL
	    }
	END

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', []).
ok
2> asn1ct:decode('RealTest', 'Real', [9,6,3,48,46,69,43,48]).
{ok,"0.E+0"}
3> asn1ct:decode('RealTest', 'Real', [9,0]).
{ok,0}
% Until now everything is more or less OK.
4> asn1ct:decode('RealTest', 'RealWrapper', [48,8, 9,6,3,48,46,69,43,48]).
{ok,{'RealWrapper',"0.E+0"}}
% Here comes the trouble:
6> asn1ct:decode('RealTest', 'RealWrapper', [48,2, 9,0]).
{error,{asn1,{{badmatch,{0,<<>>}},
              [{'RealTest',dec_RealWrapper,3},
               {'RealTest',decode,2},
               {asn1rt,decode,3},
               {erl_eval,do_apply,5},
               {shell,exprs,7},
               {shell,eval_exprs,7},
               {shell,eval_loop,3}]}}}

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
lionet.info/asn1c


More information about the erlang-bugs mailing list