summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörmungandrk <github@zerodaysec.org>2026-01-09 10:22:01 +0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2026-03-04 15:44:14 +0900
commit669f9ad7f48c5ee4b8a12796e5652571c7ac2b3e (patch)
tree12994d69cc38c6cb8e7bb8d96255b5eea171a54c
parent6cd7b1a1e9e45dd4c43c5cefc421b4c0709cdbd7 (diff)
Fix integer overflow checks in enumerator
-rw-r--r--enumerator.c5
1 files 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 <float.h>
#endif
+#include <limits.h>
#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;
}