Repository navigation
Disallow converting a buffer into itself in primitive_convert - #19918
Merged
nobu merged 1 commit intoNov 16, 2026
Merged
Conversation
Encoding::Converter#primitive_convert resizes output and updates RSTRING_LEN(output) before reading RSTRING_PTR(input) and RSTRING_LEN(input). When input and output resolve to the same String object (directly or via #to_str), rb_econv_convert reads beyond the original input length and corrupts buffer accounting. Raise ArgumentError when input == output, matching Array#pack and StringIO#read.
nobu
enabled auto-merge (rebase)
November 16, 2026 10:42
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.
Encoding::Converter#primitive_convert(econv_primitive_convertintranscode.c) resizesoutputand updatesRSTRING_LEN(output)before readingRSTRING_PTR(input)andRSTRING_LEN(input). Wheninputandoutputresolve to the sameStringobject (either directly or via#to_str),rb_econv_convertreads beyond the original input length and corrupts buffer accounting.Reject self-aliasing with
ArgumentError("cannot convert into the source string"), matchingArray#pack(93f1010f70) andStringIO#read/pread(1d2d4ac734), while preserving Copy-on-Write behavior for distinctStringobjects (src.dup).