Skip to content

Commit

Permalink
range.c: detect integer overflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Apr 3, 2022
1 parent 3dabd18 commit 8aec568
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/range.c
Expand Up @@ -362,9 +362,13 @@ range_num_to_a(mrb_state *mrb, mrb_value range)
mrb_int len;

if (mrb_int_sub_overflow(b, a, &len)) {
too_long:
mrb_raise(mrb, E_RANGE_ERROR, "integer range too long");
}
if (!RANGE_EXCL(r)) len++;
if (!RANGE_EXCL(r)) {
if (len == MRB_INT_MAX) goto too_long;
len++;
}
ary = mrb_ary_new_capa(mrb, len);
for (mrb_int i=0; i<len; i++) {
mrb_ary_push(mrb, ary, mrb_int_value(mrb, a+i));
Expand Down

0 comments on commit 8aec568

Please sign in to comment.