issue with erlang decoding of big numbers

Paul Mineiro paul-trapexit@REDACTED
Sat Jun 13 08:36:27 CEST 2009


hi.

i'm tracking down an issue with tcerl

http://code.google.com/p/tcerl/issues/detail?id=4

and it appears related to the erl_interface code to handle big nums.  i'll
focus on SMALL_BIG_EXT but LARGE_BIG_EXT has analogous issues.

when decoding via
ei_decode_big () from /usr/lib/erlang/lib/erl_interface-3.5.9/src/decode/decode_big.c

the digit bytes are read from the stream and the arity is forced to be
((digit_bytes + 1 / 2) and then an arity number of 16 bit values is
read, i.e., the number of bytes read is always even.  however there is
no justification for this from the spec
http://erlang.org/doc/apps/erts/erl_ext_dist.html
which indicates a base of 256 (i.e., one digit = one character) and i
can see in the shell for instance that

1> erlang:term_to_binary (9999999999).
<<131,110,5,0,255,227,11,84,2>>

i.e. after the sign bit there are 5 bytes ... but 6 will be read by
ei_decode_big () and in practice this means random garbage will be added
to the big num.

in diving in to fix this i noticed that other parts of the code are
assuming 16 bit digits, e.g., still in decode_big.c the function
I_comp() called from ei_big_comp() is comparing the values 16 bits at a
time, again apparently unmotivated from the spec.

the problem is so pervasive that i'm pausing to fix the issue to get
some guidance from the OTP team about what is intended here.  am i missing
something?

thanks,

-- p


More information about the erlang-bugs mailing list