pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1788142 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType2.java
Date Wed, 22 Mar 2017 17:17:47 GMT
Author: tilman
Date: Wed Mar 22 17:17:47 2017
New Revision: 1788142

URL: http://svn.apache.org/viewvc?rev=1788142&view=rev
Log:
PDFBOX-2852: avoid potential ClassCastException and ArrayIndexOutOfBoundsException

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType2.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType2.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType2.java?rev=1788142&r1=1788141&r2=1788142&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType2.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType2.java
Wed Mar 22 17:17:47 2017
@@ -54,24 +54,30 @@ public class PDFunctionType2 extends PDF
     {
         super(function);
 
-        if (getCOSObject().getDictionaryObject(COSName.C0) == null)
+        if (getCOSObject().getDictionaryObject(COSName.C0) instanceof COSArray)
         {
-            c0 = new COSArray();
-            c0.add(new COSFloat(0));
+            c0 = (COSArray) getCOSObject().getDictionaryObject(COSName.C0);
         }
         else
         {
-            c0 = (COSArray) getCOSObject().getDictionaryObject(COSName.C0);
+            c0 = new COSArray();
+        }
+        if (c0.size() == 0)
+        {
+            c0.add(new COSFloat(0));
         }
 
-        if (getCOSObject().getDictionaryObject(COSName.C1) == null)
+        if (getCOSObject().getDictionaryObject(COSName.C1) instanceof COSArray)
         {
-            c1 = new COSArray();
-            c1.add(new COSFloat(1));
+            c1 = (COSArray) getCOSObject().getDictionaryObject(COSName.C1);
         }
         else
         {
-            c1 = (COSArray) getCOSObject().getDictionaryObject(COSName.C1);
+            c1 = new COSArray();
+        }
+        if (c1.size() == 0)
+        {
+            c1.add(new COSFloat(1));
         }
 
         exponent = getCOSObject().getFloat(COSName.N);
@@ -97,7 +103,7 @@ public class PDFunctionType2 extends PDF
         // exponential interpolation
         float xToN = (float) Math.pow(input[0], exponent); // x^exponent
 
-        float[] result = new float[c0.size()];
+        float[] result = new float[Math.min(c0.size(),c1.size())];
         for (int j = 0; j < result.length; j++)
         {
             float c0j = ((COSNumber) c0.get(j)).floatValue();



Mime
View raw message