symfony / polyfill

PHP polyfills

Home Page:https://symfony.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

uuid_create(UUID_TYPE_TIME) seems broken on 32-bit

guilliamxavier opened this issue · comments

Run var_dump(uuid_create(UUID_TYPE_TIME)); several times with a few seconds/minutes delay between each call, here are some sample results:

  • on a 64-bit system:

    string(36) "3d18e40c-129d-11ea-94e6-61a012af7e36"
    string(36) "7dbf2f3e-129d-11ea-afb1-efd2f815ab0c"
    string(36) "95dd40d8-129d-11ea-be2a-931c452fa10d"
    string(36) "d58d1e1a-129d-11ea-93b0-9774d3d2232c"
    string(36) "007bc6c6-129e-11ea-bb10-e1b619b491ac"
    
  • on a 32-bit system:

    string(36) "3d710800-0000-1000-bc7d-81c9756e8182"
    string(36) "7de39b90-0000-1000-a067-8b759a2618f5"
    string(40) "95fa8cb0-ffff-ffffffff-91cb-b372558c0d82"
    string(40) "d5a82800-ffff-ffffffff-aac8-611f2a0e136d"
    string(36) "00c2eb80-0000-1000-9410-6b0dafe79f58"
    

    => the middle parts exhibit a problem

@lyrixx can you take a look at this ?

hmm, I see something weird here. The polyfill is expected to throw a RuntimeException when trying to generate a time-based uuid on a 32-bits PHP, saying it is unsupported. Are you actually using the polyfill, or do you have the uuid extension enabled ?

@stof I don't have the uuid extension, I am using the polyfill. On a 32-bits PHP it throws a RuntimeException when calling uuid_time(), but not for uuid_create(UUID_TYPE_TIME) (which thus returns broken values). For information, here are my results for var_dump(uuid_time('3d18e40c-129d-11ea-94e6-61a012af7e36'));:

  • on a 64-bits PHP: int(1575027713)
  • on a 32-bits PHP: RuntimeException "UUID time generation is not supported on 32-bit systems. Use the uuid extension instead."

it looks like the code for uuid_generate_time (the internal implementation of uuid_create(UUID_TYPE_TIME) is not compatible with 32-bits runtime either, but does not check for it.

@guilliamxavier It looks like I forgot this code path. Would you mind submitting a PR? If you can't or don't want to, no issue! Just tell me and I will do

@lyrixx In #210 I just copied the check of uuid_time into uuid_generate_time, feel free to review/improve