Skip to content

pgtype: reject 36-character UUIDs without hyphens in the right places - #2731

Open
thejesh23 wants to merge 1 commit into
jackc:masterfrom
thejesh23:uuid-check-hyphens
Open

thejesh23 wants to merge 1 commit into
jackc:masterfrom
thejesh23:uuid-check-hyphens

Conversation

@thejesh23

Copy link
Copy Markdown

parseUUID drops bytes 8, 13, 18 and 23 of a 36-character string without checking that they are hyphens. So UUID.Scan and UUID.UnmarshalJSON accept "a0eebc99X9c0bX4ef8Xbb6dX6bb9bd380a11". They also turn the 36-hex-digit "a0eebc999c0b4ef8bb6d6bb9bd380a11abcd" into a different UUID, a0eebc99-c0b4-f8bb-d6bb-bd380a11abcd. PostgreSQL's uuid_in rejects both inputs ("invalid input syntax for type uuid").

The fix returns the existing cannot parse UUID error when any of those four positions is not -. Canonical upper- and lower-case input and the 32-digit form parse as before. Input with hyphens in the wrong places already failed (with an encoding/hex error) and now gets the cannot parse UUID message.

TestUUIDRejectsMisplacedHyphens fails on master and passes with the fix. go test -race ./... passes locally against PostgreSQL 16 on Go 1.27. gofmt, gofumpt -extra and golangci-lint report nothing new.

AI proposal: Claude Opus 5.5 in Claude Code found the bug, wrote the test and the patch. Its prompt was an audit brief to find and verify functional bugs in pgx, then to fix one logged finding, writing the regression test first and showing it fails on master.

🤖 Generated with Claude Code

parseUUID dropped bytes 8, 13, 18 and 23 of a 36-character string without
checking that they are hyphens, so a 36-hex-digit string or one with other
separators parsed as a different UUID. PostgreSQL's uuid_in rejects both.
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 this pull request may close these issues.

1 participant