[PATCH] erl_interface: wrong decoding of strings

Romain Lenglet <>
Sat May 27 07:04:50 CEST 2006


Hi,


When the length of a string is > 65535, it is encoded as a flat 
list of small integers. A NIL tail is (very logically!) encoded 
as part of the encoded string in that case, as demonstrated by 
the attached Erlang module.

In erl_interface, the implementation of ei_decode_string handles 
both cases. However, the integers list case is wrongly handled: 
the NIL tail is not decoded as it should.

Attached are two versions of my patch for that bug:

- ei_decode_string.patch is to be applied against erl_interface 
version 3.5.5.

- ei_x_decode_string.patch must be applied after the three 
patches that I sent on 2006-05-15, to patch the 
ei_x_decode_string function instead.
http://www.erlang.org/ml-archive/erlang-bugs/200605/msg00007.html

By the way, none of those patches has been applied in the latest 
snapshots. Any prediction about when they will be applied (if 
ever)?


Regards,

-- 
Romain LENGLET
-------------- next part --------------
-module(teststring).

-export([start/0]).

start() ->
    test_string_encoding(70000),
    test_string_encoding(10).

test_string_encoding(Size) ->
    String = string:copies("b", Size),
    Bin = term_to_binary(String),
    if
        Size > 65535 -> % 65535==MAX_STRING_LEN in externals.c
            analyze_list(Bin);
        true ->
            analyze_string(Bin)
    end.

analyze_string(Bin) ->
    <<131, 107, Size:16, Bin2/binary>> = Bin,
    io:format("string size: ~w~n", [Size]),
    Bin3 = read_chars(Size, Bin2),
    0 = size(Bin3). % ***** No NIL tail. *****

analyze_list(Bin) ->
    <<131, 108, Size:32, Bin2/binary>> = Bin,
    io:format("list size: ~w~n", [Size]),
    Bin3 = read_small_ints(Size, Bin2),
    <<106>> = Bin3. % ***** There is a NIL tail at the end! *****

read_chars(0, Bin) ->
    Bin;
read_chars(Count, Bin) ->
    <<$b, Bin2/binary>> = Bin,
    read_chars(Count-1, Bin2).

read_small_ints(0, Bin) ->
    Bin;
read_small_ints(Count, Bin) ->
    <<97, $b, Bin2/binary>> = Bin,
    read_small_ints(Count-1, Bin2).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ei_decode_string.patch
Type: text/x-diff
Size: 402 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20060527/6b44e412/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ei_x_decode_string.patch
Type: text/x-diff
Size: 642 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20060527/6b44e412/attachment-0001.bin>


More information about the erlang-bugs mailing list