fix: Avoid overlay panic on valid Unicode input, Postgres compatibility#22046
Open
neilconway wants to merge 1 commit intoapache:mainfrom
Open
fix: Avoid overlay panic on valid Unicode input, Postgres compatibility#22046neilconway wants to merge 1 commit intoapache:mainfrom
overlay panic on valid Unicode input, Postgres compatibility#22046neilconway wants to merge 1 commit intoapache:mainfrom
Conversation
kosiew
reviewed
May 7, 2026
Contributor
There was a problem hiding this comment.
@neilconway
Nice improvement overall. I just had one small performance suggestion around the four-argument overlay path.
| if start_pos < 1 { | ||
| return exec_err!("negative substring length not allowed"); | ||
| } | ||
| let string_char_len = string.chars().count() as i64; |
Contributor
There was a problem hiding this comment.
Small optimization idea: the four-argument path calls string.chars().count() to clamp len, but overlay_one ends up computing the character length again internally. Since overlay_one already handles lengths that extend past the end of the string, it might be simpler to pass len through directly or move the clamp logic into overlay_one so we avoid the extra Unicode scan per row.
kosiew
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
overlaypanics on valid utf-8 input #22044.overlaybehavior inconsistent with Postgres / SQL spec #22045.Rationale for this change
overlaymixed up character-based and byte-based indexing, which resulted in either panicking or returning incorrect results on multi-byte Unicode input. While looking at this, I also fixed a few places whereoverlay's behavior was inconsistent with Postgres and the SQL spec, refactored the code, and added a benchmark.What changes are included in this PR?
start <= 0errorsAre these changes tested?
Yes, and new tests added.
Are there any user-facing changes?
Yes. The behavior of
overlayhas changed for multibyte Unicode inputs, as well as the edge cases enumerated above.