From 669f9ad7f48c5ee4b8a12796e5652571c7ac2b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rmungandrk?= Date: Fri, 9 Jan 2026 10:22:01 +0700 Subject: Fix integer overflow checks in enumerator --- enumerator.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/enumerator.c b/enumerator.c index d2819e4049..df263d8247 100644 --- a/enumerator.c +++ b/enumerator.c @@ -18,6 +18,7 @@ #include #endif +#include #include "id.h" #include "internal.h" #include "internal/class.h" @@ -3963,7 +3964,7 @@ arith_seq_first(int argc, VALUE *argv, VALUE self) ary = rb_ary_new_capa((n < len) ? n : len); while (n > 0 && i < end) { rb_ary_push(ary, LONG2FIX(i)); - if (i + unit < i) break; + if (i > LONG_MAX - unit) break; i += unit; --n; } @@ -3976,7 +3977,7 @@ arith_seq_first(int argc, VALUE *argv, VALUE self) ary = rb_ary_new_capa((n < len) ? n : len); while (n > 0 && i > end) { rb_ary_push(ary, LONG2FIX(i)); - if (i + unit > i) break; + if (i < LONG_MIN - unit) break; i += unit; --n; } -- cgit v1.2.3