[erlang-questions] Binary matching problem

Kostis Sagonas <>
Mon Feb 25 16:36:10 CET 2008


Tomas Stejskal wrote:
> It doesn't really work for me. I have erlang R12B-1 and it seems you've 
> tried it out on version R11B5, maybe it's a bug in R12.

This appears to be a BEAM compiler bug in R12B.  I cannot test it in 
vanilla R12B, but it's present even in the current development version, 
so I am certain it is the same problem.

Eshell V5.6.2  (abort with ^G)
1> c(id3_v1).
{ok,id3_v1}
2> id3_v1:read_v1_or_v11_tag("id3_v1.mp3").
error


Incidentally, the problem disappears if you compile to native code via 
Core Erlang (but not via BEAM):

3> hipe:c(id3_v1, [core]).
{ok,id3_v1}
4> id3_v1:read_v1_or_v11_tag("id3_v1.mp3").
{ok,{"ID3v1",
      [{title,<<68,117,154,105,232,107,121>>},
       {artist,<<"Daniel Landa">>},
       {album,<<"Best Of">>}]}}


The problem is most probably due to generating erroneous control flow.
In the list of instructions:

     {test,bs_start_match2,{f,15},[{x,0},1,0,{x,0}]}
     {test,bs_match_string,{f,15},[{x,0},24,<<"TAG">>]}
     {test,bs_get_binary2,
           {f,15},
           [{x,0},1,{integer,30},8,{field_flags,0},{x,1}]}
     {test,bs_get_binary2,
           {f,15},
           [{x,0},2,{integer,30},8,{field_flags,0},{x,2}]}
     {test,bs_get_binary2,
           {f,15},
           [{x,0},3,{integer,30},8,{field_flags,0},{x,3}]}
     {test,bs_skip_bits2,
           {f,15},
           [{x,0},{integer,4},8,{field_flags,0}]}
     {test,bs_skip_bits2,
           {f,14},
           [{x,0},{integer,28},8,{field_flags,0}]}
     {test,bs_get_integer2,
           {f,15},                              <---------------
           [{x,0},4,{integer,8},1,{field_flags,0},{x,4}]}
     {test,bs_get_integer2,
           {f,15},                              <---------------
           [{x,0},5,{integer,8},1,{field_flags,0},{x,5}]}
     {test,bs_test_tail2,{f,15},[{x,0},8]}      <---------------
     {test,is_eq_exact,{f,15},[{x,4},{integer,0}]} <------------
     ..........

the labels with the arrows should read {f,14} instead
(and perhaps there should be some bs_restore instructions in label 14).

Bjorn, now do your magic ;-)

Kostis



More information about the erlang-questions mailing list