diff options
| author | Jörmungandrk <github@zerodaysec.org> | 2026-01-09 10:22:01 +0700 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2026-03-07 13:40:05 +0900 |
| commit | a93ff4880da5c4e56f7ec2066a9c3f7748892231 (patch) | |
| tree | 99fc560ae2f9ccd11cc038abc272c943f47c5e87 | |
| parent | 46f51cb3a26e5bfc92251e7971697a9c31bcab44 (diff) | |
Fix integer overflow checks in enumerator
| -rw-r--r-- | enumerator.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/enumerator.c b/enumerator.c index faaa77cb49..0828745c18 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" @@ -3971,7 +3972,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; } @@ -3984,7 +3985,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; } |
