avtobiff / erlang-uuid

Erlang UUID
https://github.com/avtobiff/erlang-uuid
GNU Lesser General Public License v3.0
113 stars 77 forks source link

Generating invalid UUIDs. #19

Open cmeiklejohn opened 6 years ago

cmeiklejohn commented 6 years ago
17:19:00.019 [info] Application lager started on node nonode@nohost
17:19:00.020 [info] Distributed Erlang is not enabled, generating UUID.
17:19:00.022 [info] Generated UUID: <<158,154,190,66,38,226,17,232,155,216,0,0,0,0>>, converting to string.
17:19:00.022 [error] CRASH REPORT Process <0.1006.0> with 0 neighbours exited with reason: bad argument in uuid:to_string/1 line 238
17:19:00.023 [error] CRASH REPORT Process <0.1004.0> with 0 neighbours exited with reason: {{error,{badarg,[{uuid,to_string,1,[{file,"/tmp/exlam/deps/uuid/src/uuid.erl"},{line,238}]},

This is Amazon Linux.

Now, when I generate identifiers locally, with the same version of Erlang, I'm getting 16 byte identifiers. But, when I run it here, as you can see from the binary above, it's only 14 bytes. This is causing the uuid:to_string method to throw, because it doesn't match at line 238. Any thoughts on why this would happen on a particular variant of Linux?

I'm using uuid4().

avtobiff commented 5 years ago

Sorry for not having time to look into this until now.

What environment is used? (erlang-uuid, Errlang, OS versions; from source or package manager etc?)

The UUID you supplied is probably not v1 but v4. Padding to correct length yields UUIDv1.

1> uuid:version(<<158,154,190,66,38,226,17,232,155,216,0,0,0,0>>).    
** exception error: bad argument
     in function  uuid:version/1 (src/uuid.erl, line 348)
2> uuid:version(<<158,154,190,66,38,226,17,232,155,216,0,0,0,0,0,0>>).
1

I suspect that the UUIDv1 somehow use a MAC address that are only zeroes and this does not end up in a 48 bit wide binary but less.

Another suggestion is that this problem arises due to Erlang Time API changes.