summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2022-07-21 14:50:44 +0200
committerJean Boussier <jean.boussier@gmail.com>2022-07-21 18:43:45 +0200
commit79406e3600862bbb6dcdd7c5ef8de1978e6f916c (patch)
tree72dabd6309768b702d7d740b2af97688fea4a973
parent5b21e94bebed90180d8ff63dad03b8b948361089 (diff)
downloadruby-79406e3600862bbb6dcdd7c5ef8de1978e6f916c.tar.gz
objspace_dump.c: skip dumping method name if not pure ASCII
Sidekiq has a method named `❨╯°□°❩╯︵┻━┻`which corrupts heap dumps. Normally we could just dump is as is since it's valid UTF-8 and need no escaping. But our code to escape control characters isn't UTF-8 aware so it's more complicated than it seems. Ultimately since the overwhelming majority of method names are pure ASCII, it's not a big loss to just skip it.
-rw-r--r--ext/objspace/objspace_dump.c6
-rw-r--r--test/objspace/test_objspace.rb13
2 files changed, 17 insertions, 2 deletions
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c
index e4f1216a9a..b954fe32fc 100644
--- a/ext/objspace/objspace_dump.c
+++ b/ext/objspace/objspace_dump.c
@@ -547,8 +547,10 @@ dump_object(VALUE obj, struct dump_config *dc)
}
if (RTEST(ainfo->mid)) {
VALUE m = rb_sym2str(ainfo->mid);
- dump_append(dc, ", \"method\":");
- dump_append_string_value(dc, m);
+ if (dump_string_ascii_only(RSTRING_PTR(m), RSTRING_LEN(m))) {
+ dump_append(dc, ", \"method\":");
+ dump_append_string_value(dc, m);
+ }
}
dump_append(dc, ", \"generation\":");
dump_append_sizet(dc, ainfo->generation);
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 1392447e4f..59ab8e7adc 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -725,4 +725,17 @@ class TestObjSpace < Test::Unit::TestCase
assert_equal '42', out[2]
end
end
+
+ def test_utf8_method_names
+ obj = ObjectSpace.trace_object_allocations do
+ utf8_❨╯°□°❩╯︵┻━┻
+ end
+ assert_nil JSON.parse(ObjectSpace.dump(obj))["method"]
+ end
+
+ private
+
+ def utf8_❨╯°□°❩╯︵┻━┻
+ "1" + "2"
+ end
end