diff options
author | Peter Zhu <[email protected]> | 2024-02-08 10:43:50 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2024-02-13 11:05:56 -0500 |
commit | a71d1ed83875600c174e66a8ace18e0ad451958a (patch) | |
tree | 1afb3c02d9144c14ab580a1f4f727e8c9f9c9927 /rubyparser.h | |
parent | e4272fd292e7a432150e90c8dc7d8e9aa7d07e62 (diff) |
Fix memory leak when parsing invalid hash symbol
For example:
10.times do
100_000.times do
eval('{"\xC3": 1}')
rescue EncodingError
end
puts `ps -o rss= -p #{$$}`
end
Before:
32032
48464
66112
84192
100592
117520
134096
150656
167168
183760
After:
17120
17120
17120
17120
18560
18560
18560
18560
18560
18560
Diffstat (limited to 'rubyparser.h')
-rw-r--r-- | rubyparser.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/rubyparser.h b/rubyparser.h index ab55233d6d..59f594bad0 100644 --- a/rubyparser.h +++ b/rubyparser.h @@ -1277,6 +1277,7 @@ typedef struct rb_parser_config_struct { VALUE (*id2str)(ID id); VALUE (*id2sym)(ID x); ID (*sym2id)(VALUE sym); + ID (*check_id_cstr)(const char *ptr, long len, rb_encoding *enc); /* String */ RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3) @@ -1293,10 +1294,12 @@ typedef struct rb_parser_config_struct { VALUE (*str_resize)(VALUE str, long len); VALUE (*str_new)(const char *ptr, long len); VALUE (*str_new_cstr)(const char *ptr); + VALUE (*setup_fake_str)(struct RString *fake_str, const char *name, long len, rb_encoding *enc); VALUE (*fstring)(VALUE); int (*is_ascii_string)(VALUE str); VALUE (*enc_str_new)(const char *ptr, long len, rb_encoding *enc); VALUE (*enc_str_buf_cat)(VALUE str, const char *ptr, long len, rb_encoding *enc); + int (*enc_str_coderange)(VALUE str); VALUE (*str_buf_append)(VALUE str, VALUE str2); RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0) VALUE (*str_vcatf)(VALUE str, const char *fmt, va_list ap); @@ -1361,6 +1364,7 @@ typedef struct rb_parser_config_struct { void (*encoding_set)(VALUE obj, int encindex); int (*encoding_is_ascii8bit)(VALUE obj); rb_encoding *(*usascii_encoding)(void); + int enc_coderange_broken; /* Ractor */ VALUE (*ractor_make_shareable)(VALUE obj); |