ASN1: vicious bug when using recursive message definitions

BETIS Alexandre <>
Mon May 30 17:47:39 CEST 2005

Hi all,

I have encountered a bug in the asn1rt:decode() function
when using 'recursive' message definition. Like this:


  header INTEGER,
  body Body

Body ::= CHOICE
  anInt [0] INTEGER,
  aSubBody [1] ASubBody,
  aNull [2] NULL

  body Body,


Body appears in the subBody. It is quite useful for "reply"
messages (we can include the initial message in the body
of the reply message).

This is encoded fine, but the decode function fails when the
subbody is NULL, and it seems only in this case.

Here is a sample code:




test() ->
    Msg0 = #'Msg'{header = 1,
		  body = {aSubBody, 
			  #'ASubBody'{body = {anInt, 1}, 
				      anInt = 3}}},
    {ok, Bytes0} = asn1rt:encode('Bug', 'Msg', Msg0),
    {ok, Msg0} = asn1rt:decode('Bug', 'Msg', Bytes0), %% ok

    Msg2 = #'Msg'{header = 1,
		  body = {aSubBody, 
			  #'ASubBody'{body = {aNull, 'NULL'}, 
				      anInt = 3}}},
    {ok, Bytes1} = asn1rt:encode('Bug', 'Msg', Msg2),
    Msg2 = asn1rt:decode('Bug', 'Msg', Bytes1), %%%%%%%%%%%%%%%%%%%%  FAILS!!!

Sample session:

Erlang (BEAM) emulator version 5.4.4 [source] [hipe]

Eshell V5.4.4  (abort with ^G)
1> c(bug).
2> bug:test().

=ERROR REPORT==== 30-May-2005::16:46:42 ===
Error in process <0.30.0> with exit value: 
{{badmatch,{error,{asn1,{unexpected,<<3 bytes>>}}}},

** exited: {{badmatch,{error,{asn1,{unexpected,
             {shell,eval_loop,3}]} **

Apparently, this has something to do with the size of Null being 0,
but I have yet to identify where the problem is in the code. Has anybody
ever encountered this problem? In the meantime, we will forget about NULL...


-- Alex

" Ce message et ses pièces jointes sont confidentiels et exclusivement réservés à leurs destinataires qui s'assureront de l'absence de virus. CSEE Transport n'assume aucune responsabilité au titre de ce message s'il est altéré, déformé, falsifié, indûment utilisé par des tiers ou encore s'il a causé des dommages ou pertes de toute nature.

This e-mail and any attached files are confidential and exclusively intended for its addressees who will conduct appropriate virus checks. CSEE Transport shall not be liable for the message if altered, changed, falsified, unduly used by third parties nor for any damage or loss."

More information about the erlang-questions mailing list