Skip to content

Commit b79a5f1

Browse files
committed
Raise FrozenError when a frozen String passed as a destination buffer to Encoding::Convertor#primitive_convert method
1 parent b6c229a commit b79a5f1

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Compatibility:
2929
* Add `Module#refinements` (#3039, @itarato).
3030
* Add `Refinement#refined_class` (#3039, @itarato).
3131
* Add `rb_hash_new_capa` function (#3039, @itarato).
32+
* Fix `Encoding::Converter#primitive_convert` and raise `FrozenError` when a destination buffer argument is frozen (@andrykonchin).
3233

3334
Performance:
3435

spec/ruby/core/encoding/converter/primitive_convert_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
-> { @ec.primitive_convert("","") }.should_not raise_error
1515
end
1616

17+
it "raises FrozenError when the destination buffer is a frozen String" do
18+
-> { @ec.primitive_convert("", "".freeze) }.should raise_error(FrozenError)
19+
end
20+
1721
it "accepts nil for the destination byte offset" do
1822
-> { @ec.primitive_convert("","", nil) }.should_not raise_error
1923
end

src/main/ruby/truffleruby/core/transcoding.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ def primitive_convert(source, target, offset = nil, size = nil, options = 0)
185185
source = source ? StringValue(source) : +''
186186
target = StringValue(target)
187187

188+
Primitive.check_mutable_string target
189+
188190
if Primitive.nil? offset
189191
offset = target.bytesize
190192
else

0 commit comments

Comments
 (0)