Skip to content

FromPyObject impl for uuid::Uuid broken on big-endian architectures #5160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
decathorpe opened this issue May 20, 2025 · 0 comments · Fixed by #5161
Closed

FromPyObject impl for uuid::Uuid broken on big-endian architectures #5160

decathorpe opened this issue May 20, 2025 · 0 comments · Fixed by #5161

Comments

@decathorpe
Copy link
Contributor

This is not a new failure, but until now, we only ran tests with the "default" features enabled during package builds for Fedora Linux. I realized that I could turn on the "full" feature set without additional maintenance burden, and thought that would be a good idea to increase test coverage for more features on different architectures / Python versions.

Turns out, there's test failures in the "uuid" conversion feature that we hadn't hit because that feature wasn't enabled when we ran the test suite:

---- conversions::uuid::tests::convert_uuid_v1 stdout ----
thread 'conversions::uuid::tests::convert_uuid_v1' panicked at src/conversions/uuid.rs:179:5:
assertion `left == right` failed
  left: a6cc5730-2261-11ee-9c43-2eb5a363657c
 right: 7c6563a3-b52e-439c-ee11-61223057cca6
---- conversions::uuid::tests::convert_uuid_v3 stdout ----
thread 'conversions::uuid::tests::convert_uuid_v3' panicked at src/conversions/uuid.rs:173:5:
assertion `left == right` failed
  left: 6fa459ea-ee8a-3ca4-894e-db77e160355e
 right: 5e3560e1-77db-4e89-a43c-8aeeea59a46f
---- conversions::uuid::tests::convert_uuid_v4 stdout ----
thread 'conversions::uuid::tests::convert_uuid_v4' panicked at src/conversions/uuid.rs:167:5:
assertion `left == right` failed
  left: a4f6d1b9-1898-418f-b11d-ecc6fe1e1f00
 right: 001f1efe-c6ec-1db1-8f41-9818b9d1f6a4

These failures are from pyo3 0.24.2. But this code (in src/conversions/uuid.rs) hasn't changed since it was initially added in 5c363b5 so as far as I can tell, this should always have failed (I can run those tests with pyo3 0.23 and 0.25 too, if needed).

Looking at the test code, the assertion that causes these failures (except for the trivial cases where endianness doesn't matter) is this one: https://github.com/PyO3/pyo3/blob/v0.24.2/src/conversions/uuid.rs#L148

Which is strange, because the assertion in the Python code further up seems to pass: https://github.com/PyO3/pyo3/blob/v0.24.2/src/conversions/uuid.rs#L137

So as far as I can tell, the only place that is going wrong seems to be let py_result: Uuid = py_uuid.extract().unwrap(); at https://github.com/PyO3/pyo3/blob/v0.24.2/src/conversions/uuid.rs#L147.

Indeed, the FromPyObject impl does this to convert from an 128-bit number to the UUID - Uuid::from_u128(uuid_int.to_le()) - this hard-codes converting the u128 value to little-endian bytes, which is a noop on little-endian architectures and seems to be just plain wrong on big-endian architectures.

Patching the to_le() call out makes the tests pass on all architectures. I'll submit a PR for this change shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant