Skip to content

sql: fix coordinator panic parsing Unicode-numeric durations#36846

Merged
aljoscha merged 1 commit into
MaterializeInc:mainfrom
aljoscha:sql-285-duration-unicode-panic
Jun 2, 2026
Merged

sql: fix coordinator panic parsing Unicode-numeric durations#36846
aljoscha merged 1 commit into
MaterializeInc:mainfrom
aljoscha:sql-285-duration-unicode-panic

Conversation

@aljoscha
Copy link
Copy Markdown
Contributor

@aljoscha aljoscha commented Jun 1, 2026

Duration::parse located the end of the leading number with chars().position(|c| \!char::is_numeric(c)), which returns a character index, and then sliced the string with it as a byte offset. char::is_numeric also matches multi-byte Unicode numerics (e.g. '²', '½'), so for such input the character index and byte offset diverge and the slice can land mid-character, panicking the coordinator thread:

SET statement_timeout = '²';
SET idle_in_transaction_session_timeout = '1²ms';

Use str::find, which returns a byte index suitable for slicing, and restrict the leading run to ASCII digits — exactly what the subsequent u64::parse accepts. Inputs containing Unicode numerics now cleanly return a parse error instead of panicking.

Fixes SQL-285

`Duration::parse` located the end of the leading number with
`chars().position(|c| \!char::is_numeric(c))`, which returns a *character*
index, and then sliced the string with it as a *byte* offset. `char::is_numeric`
also matches multi-byte Unicode numerics (e.g. '²', '½'), so for such input the
character index and byte offset diverge and the slice can land mid-character,
panicking the coordinator thread:

    SET statement_timeout = '²';
    SET idle_in_transaction_session_timeout = '1²ms';

Use `str::find`, which returns a byte index suitable for slicing, and restrict
the leading run to ASCII digits — exactly what the subsequent `u64::parse`
accepts. Inputs containing Unicode numerics now cleanly return a parse error
instead of panicking.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aljoscha aljoscha requested a review from a team as a code owner June 1, 2026 13:55
@aljoscha aljoscha requested a review from def- June 1, 2026 13:55
@aljoscha aljoscha changed the title sql: Fix coordinator panic parsing Unicode-numeric durations sql: fix coordinator panic parsing Unicode-numeric durations Jun 2, 2026
@ggevay ggevay self-requested a review June 2, 2026 10:11
@aljoscha aljoscha merged commit 2deb792 into MaterializeInc:main Jun 2, 2026
118 checks passed
@aljoscha aljoscha deleted the sql-285-duration-unicode-panic branch June 2, 2026 10:39
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.

2 participants