From 9d76a0ab4a582d6fefbc50a7d87a68ce86cf9c56 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Sat, 29 Jun 2024 14:05:05 +0900 Subject: [PATCH] Add RB_GC_GUARD for ast_value I think this change fixes the following assertion failure: ``` [BUG] unexpected rb_parser_ary_data_type (2114076960) for script lines ``` It seems that `ast_value` is collected then `rb_parser_build_script_lines_from` touches invalid memory address. This change prevents `ast_value` from being collected by RB_GC_GUARD. --- iseq.c | 3 ++- vm_core.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iseq.c b/iseq.c index 9c94ce355d..85d4cca000 100644 --- a/iseq.c +++ b/iseq.c @@ -971,7 +971,7 @@ iseq_translate(rb_iseq_t *iseq) } rb_iseq_t * -rb_iseq_new_with_opt(const VALUE ast_value, VALUE name, VALUE path, VALUE realpath, +rb_iseq_new_with_opt(VALUE ast_value, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, enum rb_iseq_type type, const rb_compile_option_t *option, VALUE script_lines) @@ -1004,6 +1004,7 @@ rb_iseq_new_with_opt(const VALUE ast_value, VALUE name, VALUE path, VALUE realpa rb_iseq_compile_node(iseq, node); finish_iseq_build(iseq); + RB_GC_GUARD(ast_value); return iseq_translate(iseq); } diff --git a/vm_core.h b/vm_core.h index 7bb779dfa0..3c656ff49d 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1203,7 +1203,7 @@ rb_iseq_t *rb_iseq_new (const VALUE ast_value, VALUE name, VALUE path, V rb_iseq_t *rb_iseq_new_top (const VALUE ast_value, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent); rb_iseq_t *rb_iseq_new_main (const VALUE ast_value, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt); rb_iseq_t *rb_iseq_new_eval (const VALUE ast_value, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth); -rb_iseq_t *rb_iseq_new_with_opt(const VALUE ast_value, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, +rb_iseq_t *rb_iseq_new_with_opt( VALUE ast_value, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, enum rb_iseq_type, const rb_compile_option_t*, VALUE script_lines);