Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add range checking to Array#product so the tests no longer run out of…

… memory and hang (also part of rubyspec error checking)
  • Loading branch information...
commit 3f5b7a6d958ee3bc5e9f117761a805ab7469e35d 1 parent 411a3e5
Orion Edwards [GGL] authored
Showing with 7 additions and 0 deletions.
  1. +7 −0 Languages/Ruby/Libraries/Extensions/IListOps.cs
View
7 Languages/Ruby/Libraries/Extensions/IListOps.cs
@@ -318,10 +318,17 @@ public static class IListOps {
if (self.Count == 0) {
return result;
}
+
+ int requiredCapacity = 1;
for (int i = 0; i < arrays.Length; i++) {
if (arrays[i].Count == 0) {
return result;
}
+ try {
+ requiredCapacity = checked(requiredCapacity * arrays[i].Count);
+ } catch (OverflowException) {
+ throw RubyExceptions.CreateRangeError("too big to product");
+ }
}
int[] indices = new int[1 + arrays.Length];
Please sign in to comment.
Something went wrong with that request. Please try again.