merge revision(s) 54c4694994cc3bcfea9058b22ba3e68af6aaf740: [Backport #21961]

[PATCH] marshal.c: properly freeze linked strings

	[Bug #21961]
This commit is contained in:
Hiroshi SHIBATA 2026-03-26 08:34:22 +09:00
parent fecabc3145
commit acfdc0ac88
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2
3 changed files with 18 additions and 1 deletions

View File

@ -1880,6 +1880,9 @@ r_object_for(struct load_arg *arg, bool partial, int *ivp, VALUE extmod, int typ
}
v = (VALUE)link;
if (!st_lookup(arg->partial_objects, (st_data_t)v, &link)) {
if (arg->freeze && RB_TYPE_P(v, T_STRING)) {
v = rb_str_to_interned_str(v);
}
v = r_post_proc(v, arg);
}
break;

View File

@ -971,5 +971,19 @@ class TestMarshal < Test::Unit::TestCase
refute_predicate Object, :frozen?
refute_predicate Kernel, :frozen?
end
def test_linked_strings_are_frozen
str = "test"
str.instance_variable_set(:@self, str)
source = [str, str]
objects = Marshal.load(encode(source), freeze: true)
assert_predicate objects[0], :frozen?
assert_predicate objects[1], :frozen?
assert_same objects[0], objects[1]
assert_same objects[0], objects[0].instance_variable_get(:@self)
assert_same objects[1], objects[1].instance_variable_get(:@self)
assert_same objects[0].instance_variable_get(:@self), objects[1].instance_variable_get(:@self)
end
end
end

View File

@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 10
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 203
#define RUBY_PATCHLEVEL 204
#include "ruby/version.h"
#include "ruby/internal/abi.h"