[erlang-questions] Decoding term with ei that has a map with long atom keys

Erik Axling <>
Thu Dec 11 09:07:15 CET 2014


Embarrasingly enough I simply allocated a too small buffer in my C program.
I based my code on
http://erlangcentral.org/wiki/index.php?title=How_to_use_ei_to_marshal_binary_terms_in_port_programs
which allocated a 128 byte sized buffer for the messages. Increasing this
size solved this problem. Not entirely sure why though as the code seems to
realloc the buffer if the size is larger then the previously allocated
buffer but I should be able to figure it out though.

/axling

On Thu, Dec 11, 2014 at 7:43 AM, Erik Axling <> wrote:

> Ok. I'll see if I can narrow it down some more. Thanks for checking this
> case at least.
>
> /axling
>
> 11 dec 2014 kl. 01:45 skrev Björn-Egil Dahlberg <
> >:
>
> I think something else is going here.
>
> Just to be sure, I added your specific example to erl_interface tests and
> that passed without problems.
>
> If ei_decode_version(but, &index, &version) fails, that typically means
> you have corrupted your binary somewhere.
> ei_decode_version checks if the leading byte of the binary is 131 (the
> current version).
>
> // Björn-Egil
>
> 2014-12-11 0:18 GMT+01:00 Erik Axling <>:
>
>> Hello!
>>
>> I ran into an issue where ei_decode_version seems to fail when trying to
>> decode a term that contains a map with large atom keys.
>>
>> My message that is sent to the port looks something like this:
>>
>> erlang:port_command(Port, term_to_binary({cmd, type, undefined,
>> #{asdadasdsadasdasdasdasda=>sadsadsada,asdsadsadsadsadsadsadasdasdsadasb=>sdsdsdsdsdb})).
>>
>> This fails in my port pretty quickly when doing ei_decode_version(but,
>> &index, &version).
>>
>> It works when i send a message similar to
>>
>> erlang:port_command(Port, term_to_binary({cmd, type, undefined, #{b=>s,
>> a=>s})).
>>
>> Erlang version is :
>> Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:4:4] [async-threads:10]
>> [hipe] [kernel-poll:false]
>>
>> Eshell V6.2  (abort with ^G)
>>
>> Running this on a Macbook Air if that is interesting.
>>
>>
>> I know that the maps feature is still a bit experimental so just would
>> like to know if this is a known issue of if I'm understanding something
>> wrong?
>>
>> /axling
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141211/9fd4a131/attachment.html>


More information about the erlang-questions mailing list