Permalink
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...
Orion Edwards [GGL]
Orion Edwards [GGL] committed Jan 5, 2012
1 parent 411a3e5 commit 3f5b7a6d958ee3bc5e9f117761a805ab7469e35d
Showing with 7 additions and 0 deletions.
  1. +7 −0 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];

0 comments on commit 3f5b7a6

Please sign in to comment.