python / cpython

The Python programming language
https://www.python.org
Other
62.39k stars 29.96k forks source link

AssertionError in test_uuid on NetBSD: Expected UUID version 1, but got version 4 #124228

Open furkanonder opened 19 hours ago

furkanonder commented 19 hours ago

Bug report

Bug description:

home# ./python -m test test_uuid
Using random seed: 2311813199
0:00:00 load avg: 0.11 Run 1 test sequentially in a single process
0:00:00 load avg: 0.11 [1/1] test_uuid
test test_uuid failed -- Traceback (most recent call last):
  File "/home/blue/cpython/Lib/test/test_uuid.py", line 496, in test_uuid1
    equal(u.version, 1)
    ~~~~~^^^^^^^^^^^^^^
AssertionError: 4 != 1

test_uuid failed (1 failure)

== Tests result: FAILURE ==

1 test failed:
    test_uuid

Total duration: 1.1 sec
Total tests: run=72 failures=1 skipped=13
Total test files: run=1/1 failed=1
Result: FAILURE

CPython versions tested on:

CPython main branch

Operating systems tested on:

Other

Linked PRs

furkanonder commented 19 hours ago

In NetBSD the py_uuid_generate_time_safe function generates a uuid using the uuid_create and uuid_enc_be functions. The uuid version generated is 4.

An example to reproduce the situation;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uuid.h>

int main() {
    uuid_t *uuid;
    unsigned char encoded_uuid[16];

    uuid = malloc(sizeof(struct uuid));
    if (!uuid) {
        fprintf(stderr, "Memory allocation failed\n");
        return 1;
    }

    uuid_create(uuid, NULL);
    uuid_enc_be(encoded_uuid, uuid);

    printf("Converted UUID: ");
    for (int i = 0; i < 16; i++) {
        printf("%02x", encoded_uuid[i]);
        if ((i == 3 || i == 5 || i == 7 || i == 9) && i < 15) {
            printf("-");
        }
    }

    printf("\n");
    free(uuid);

    return 0;
}
home$ gcc uuid_example.c -o uuid_example
home$ ./uuid_example
Converted UUID: 18bea948-0a56-4b61-9973-10ce1a098203
home$ ./uuid_example
Converted UUID: 1b2f696c-942e-490d-bfa6-d49246de6ad2
home$ ./uuid_example
Converted UUID: f9aa5345-9ac2-4528-8817-bf5b8a60ba4d