diff options
| author | Randy Stauner <randy@r4s6.net> | 2026-02-09 10:47:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-09 09:47:03 -0800 |
| commit | 584c3b6465ec40226687e9699d2b652d9ad31a8f (patch) | |
| tree | 58d0ee78751c1bd8c3ab481ea072fd024bdc49fe | |
| parent | e4dd078a2734f1f3b7169feb4da8c68587effc6e (diff) | |
[Backport #21866] Fix integer overflow checks in enumerator (#16088)
Fix integer overflow checks in enumerator
Co-authored-by: Jörmungandrk <github@zerodaysec.org>
| -rw-r--r-- | enumerator.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/enumerator.c b/enumerator.c index 89ec503530..63a665c686 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" @@ -4000,7 +4001,7 @@ arith_seq_take(VALUE self, VALUE num) 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; } @@ -4013,7 +4014,7 @@ arith_seq_take(VALUE self, VALUE num) 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; } |
