changeset 9774:3000af712724

8155903: Crash while running imported/w3c/canvas/2d.gradient.interpolate.overlap2.html Reviewed-by: flar
author mbilla
date Fri, 13 May 2016 01:30:02 +0530
parents 63b2d809f75c
children 3571831b0b9d
files modules/graphics/src/main/java/com/sun/prism/impl/paint/MultipleGradientContext.java
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/prism/impl/paint/MultipleGradientContext.java	Thu May 12 19:57:11 2016 +0300
+++ b/modules/graphics/src/main/java/com/sun/prism/impl/paint/MultipleGradientContext.java	Fri May 13 01:30:02 2016 +0530
@@ -207,17 +207,19 @@
         // to explode.  If the estimated size is too large, break to using
         // separate arrays for each interval, and using an indexing scheme at
         // look-up time.
-        int estimatedSize = 0;
-        for (int i = 0; i < normalizedIntervals.length; i++) {
+        float estimatedSize = 0.0f;
+        for (int i = 0; i < normalizedIntervals.length
+                && Float.isFinite(estimatedSize); i++) {
             estimatedSize += (normalizedIntervals[i]/Imin) * GRADIENT_SIZE;
         }
 
-        if (estimatedSize > MAX_GRADIENT_ARRAY_SIZE) {
-            // slow method
-            calculateMultipleArrayGradient(normalizedColors);
-        } else {
+        if (estimatedSize <= MAX_GRADIENT_ARRAY_SIZE) {
             // fast method
             calculateSingleArrayGradient(normalizedColors, Imin);
+        } else {
+            // fallback to slow method if
+            // |estimatedSize| is > MAX_GRADIENT_ARRAY_SIZE or NaN or Infinity.
+            calculateMultipleArrayGradient(normalizedColors);
         }
     }