You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2020/06/27 13:55:42 UTC

svn commit: r1879275 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java

Author: lehmi
Date: Sat Jun 27 13:55:42 2020
New Revision: 1879275

URL: http://svn.apache.org/viewvc?rev=1879275&view=rev
Log:
PDFBOX-4892: replace loop with array copy, close input stream as MemoryCacheImageInputStream doesn't close the source input stream

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java?rev=1879275&r1=1879274&r2=1879275&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType0.java Sat Jun 27 13:55:42 2020
@@ -17,6 +17,8 @@
 package org.apache.pdfbox.pdmodel.common.function;
 
 import java.io.IOException;
+import java.io.InputStream;
+
 import javax.imageio.stream.ImageInputStream;
 import javax.imageio.stream.MemoryCacheImageInputStream;
 
@@ -304,10 +306,7 @@ public class PDFunctionType0 extends PDF
                 {
                     coord[step] = inPrev[step];
                     int[] tmpSample = getSamples()[calcSampleIndex(coord)];
-                    for (int i = 0; i < numberOfOutputValues; ++i)
-                    {
-                        resultSample[i] = tmpSample[i];
-                    }
+                    System.arraycopy(tmpSample, 0, resultSample, 0, numberOfOutputValues);
                     return resultSample;
                 }
                 coord[step] = inPrev[step];
@@ -389,12 +388,12 @@ public class PDFunctionType0 extends PDF
                 samples = new int[arraySize][nOut];
                 int bitsPerSample = getBitsPerSample();
                 int index = 0;
-                try
+                try (InputStream is = getPDStream().createInputStream())
                 {
                     // PDF spec 1.7 p.171:
                     // Each sample value is represented as a sequence of BitsPerSample bits. 
                     // Successive values are adjacent in the bit stream; there is no padding at byte boundaries.
-                    try (ImageInputStream mciis = new MemoryCacheImageInputStream(getPDStream().createInputStream()))
+                    try (ImageInputStream mciis = new MemoryCacheImageInputStream(is))
                     {
                         for (int i = 0; i < arraySize; i++)
                         {