⚡ Sangsakala Proxy 🏠 Home
Skip to content

gh-139122: Fix the C UUID error message for badly formed hex strings - #161300

Open
RaphaelFakhri wants to merge 1 commit into
python:mainfrom
RaphaelFakhri:gh-139122-uuid-hex-error-message
Open

RaphaelFakhri wants to merge 1 commit into
python:mainfrom
RaphaelFakhri:gh-139122-uuid-hex-error-message

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

from_hex() in Modules/_uuidmodule.c passes the hex object to PyErr_Format() with a %s conversion, which expects a const char *. The message then shows bytes from the object header instead of the input, and reading it is undefined behavior:

>>> import uuid
>>> uuid.UUID('123456781234567812345678123456789')
Traceback (most recent call last):
  ...
ValueError: invalid UUID '\x05': decodes to more than 16 bytes

The pure-Python implementation raises ValueError('badly formed hexadecimal UUID string') for the same input. The C version already uses that message for its other hex errors.

This change makes the two remaining error paths in from_hex() (more than 16 bytes, fewer than 16 bytes) raise the same message. python -m uuid -u uuid3 -n <bad namespace> then prints the documented error again.

The new test test_bad_hex_error_message runs against both implementations. Five of its subtests fail on the C implementation without the fix.

The C implementation is not released yet, so no NEWS entry is added (other follow-ups to gh-139122 use "skip news").

@bedevere-app bedevere-app Bot added awaiting review type-feature A feature request or enhancement labels Nov 4, 2026
@bedevere-app

bedevere-app Bot commented Nov 4, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant