[erlang-bugs] binary_to_term--are these bugs?

John Hughes john.hughes@REDACTED
Fri Jan 18 11:48:11 CET 2008


I've found some behaviour that I didn't expect in binary_to_term in R12B.
I'm testing the QuickCheck property

 

prop_binary_to_term() ->

    ?FORALL(Bin,binary(),

              case catch binary_to_term(Bin) of

                   {'EXIT',{badarg,_}} ->

                       true;

                   Term ->

                       Bins = term_to_binaries(Term),

                       ?WHENFAIL(io:format("~p~n~p~n",[Term,Bins]),

                                   lists:any(fun(Bin2)->Bin=:=Bin2
end,Bins))

              end).

 

term_to_binaries(T) ->

    lists:usort([term_to_binary(T,[{compressed,Level},{minor_version,Ver}])

                    || Level <- lists:seq(0,9),

                       Ver <- [0,1]]).

 

binary() ->

    ?LET(L,list(choose(0,255)),

           list_to_binary(L)).

 

The property says that any binary that binary_to_term successfully decodes,
must be an encoding of that term using some compression level and minor
version (the encoding options mentioned in the documentation). But it fails,
on, for example:

 

<<131,97,0,0>>

0

[<<131,97,0>>]

 

Or

 

<<131,106,0>>

[]

[<<131,106>>]

 

Or

 

<<131,106,191,1,69,44,184,180,64>>

[]

[<<131,106>>]

 

Or

 

<<131,67,0>>

'_'

[<<131,100,0,1,95>>]

 

where the output in each case is the binary, the term it decodes to, and the
list of all possible encodings produced by term_to_binary.

 

Is this a bug?

 

John

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20080118/8091b8bc/attachment.htm>


More information about the erlang-bugs mailing list