From 38882aeceed1a9802ba242c947bb60bb7746897c Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 7 Jul 2025 14:30:42 +0900 Subject: [PATCH] array.c: add recursion detection to Array#== and Array#eql? Prevent SystemStackError when comparing arrays with circular references. Uses the same recursion detection mechanism as Hash equality methods. Co-authored-by: Claude --- src/array.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/array.c b/src/array.c index 7b74aaae4..bb4aeb4cf 100644 --- a/src/array.c +++ b/src/array.c @@ -1669,6 +1669,11 @@ mrb_ary_eq(mrb_state *mrb, mrb_value ary1) if (n == 1) return mrb_true_value(); if (n == 0) return mrb_false_value(); + /* Check for recursion */ + if (MRB_RECURSIVE_BINARY_P(mrb, MRB_OPSYM(eq), ary1, ary2)) { + return mrb_false_value(); + } + int ai = mrb_gc_arena_save(mrb); for (mrb_int i=0; i