Skip to content

fix(promql): prevent panic in trimStringByBytes on invalid UTF-8#17735

Merged
beorn7 merged 1 commit intoprometheus:mainfrom
aknuds1:arve/trim-string-by-bytes
Jan 27, 2026
Merged

fix(promql): prevent panic in trimStringByBytes on invalid UTF-8#17735
beorn7 merged 1 commit intoprometheus:mainfrom
aknuds1:arve/trim-string-by-bytes

Conversation

@aknuds1
Copy link
Contributor

@aknuds1 aknuds1 commented Dec 24, 2025

Add bounds check to prevent index out of range panic when trimStringByBytes receives a string containing only UTF-8 continuation bytes (0x80-0xBF). Previously, the loop would decrement size below 0 when no valid rune start byte was found, causing a panic.

A malicious query string with only continuation bytes could crash the Prometheus server via the ActiveQueryTracker before the query was parsed or validated.

Which issue(s) does the PR fix:

Does this PR introduce a user-facing change?

[BUGFIX] PromQL: Prevent query strings containing only UTF-8 continuation bytes from crashing Prometheus

Add bounds check to prevent index out of range panic when
trimStringByBytes receives a string containing only UTF-8 continuation
bytes (0x80-0xBF). Previously, the loop would decrement size below 0
when no valid rune start byte was found, causing a panic.

A malicious query string with only continuation bytes could crash
the Prometheus server via the ActiveQueryTracker before the query
was parsed or validated.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@aknuds1 aknuds1 force-pushed the arve/trim-string-by-bytes branch from 0560eae to 65f8482 Compare January 24, 2026 15:06
Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by the bug scrub.

@beorn7 beorn7 merged commit f390163 into prometheus:main Jan 27, 2026
53 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants