Repository navigation
Do not hang when padding a string with an empty string - #1195
Merged
Merged
Conversation
`pad(string, len, "")` looped forever: the padding adds zero characters per iteration, so the length never reaches `len`. The loop runs inside the native function, so `max_operations` and `on_progress` cannot stop it either. An empty padding string now leaves the string unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ImTheSquid
approved these changes
Oct 23, 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.
padwith an empty padding string never returns:pad_with_stringappendspaddinguntil the character count reacheslen, but an empty padding adds nothing, so thewhileloop never ends. The loop runs inside the native function, somax_operationsandon_progresscan't interrupt it: withset_max_operations(1_000),set_max_string_size(100)and anon_progresscallback that terminates after 20 operations, the script above still hangs. For an engine that runs untrusted scripts, that's an easy way to lock up the host thread.The fix returns early when
paddingis empty and leaves the string unchanged, the same as whenlenisn't larger than the string. The doc comment now says so.Added
test_string_padtotests/string.rs. Without the fix it never finishes; with it, it passes.cargo test --testspasses, and the string tests also pass withno_object,no_index,unchecked,syncandinternals,grain.Found by calling every standard-library function with edge-case arguments; this was the only hang or panic it turned up.
I didn't add a CHANGELOG entry because 1.27.0 is already released and there's no section for the next version yet. Happy to add one wherever you prefer.
I used Claude Code to write this change.