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/05/16 17:20:09 UTC

svn commit: r1877825 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: ./ cos/ io/ pdfparser/ pdmodel/interactive/digitalsignature/

Author: lehmi
Date: Sat May 16 17:20:09 2020
New Revision: 1877825

URL: http://svn.apache.org/viewvc?rev=1877825&view=rev
Log:
revert accidentally commited changes

Added:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBufferedFileInputStream.java
      - copied unchanged from r1877822, pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBufferedFileInputStream.java
Removed:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBufferedFile.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessMemoryMappedFile.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessReadView.java
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSInputStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/EndstreamOutputStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java?rev=1877825&r1=1877824&r2=1877825&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/Loader.java Sat May 16 17:20:09 2020
@@ -26,7 +26,7 @@ import java.io.InputStream;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.MemoryUsageSetting;
 import org.apache.pdfbox.io.RandomAccessBuffer;
-import org.apache.pdfbox.io.RandomAccessBufferedFile;
+import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
 import org.apache.pdfbox.io.RandomAccessRead;
 import org.apache.pdfbox.io.ScratchFile;
 import org.apache.pdfbox.pdfparser.FDFParser;
@@ -297,7 +297,7 @@ public class Loader
             MemoryUsageSetting memUsageSetting) throws IOException
     {
         @SuppressWarnings({ "squid:S2095" }) // raFile not closed here, may be needed for signing
-        RandomAccessBufferedFile raFile = new RandomAccessBufferedFile(file);
+        RandomAccessBufferedFileInputStream raFile = new RandomAccessBufferedFileInputStream(file);
         try
         {
             return Loader.loadPDF(raFile, password, keyStore, alias, memUsageSetting);
@@ -308,21 +308,8 @@ public class Loader
             throw ioe;
         }
     }
-    /**
-     * Parses a PDF.
-     * 
-     * @param rafile          RandomAccessRead of the file to be loaded
-     * @param password        password to be used for decryption
-     * @param keyStore        key store to be used for decryption when using public key security
-     * @param alias           alias to be used for decryption when using public key security
-     * @param memUsageSetting defines how memory is used for buffering PDF streams
-     * 
-     * @return loaded document
-     * 
-     * @throws IOException in case of a file reading or parsing error
-     */
-    public static PDDocument loadPDF(RandomAccessRead raFile,
-            String password,
+
+    public static PDDocument loadPDF(RandomAccessBufferedFileInputStream raFile, String password,
             InputStream keyStore, String alias, MemoryUsageSetting memUsageSetting)
             throws IOException
     {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1877825&r1=1877824&r2=1877825&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Sat May 16 17:20:09 2020
@@ -165,14 +165,6 @@ public class COSDocument extends COSBase
         return stream;
     }
 
-    public COSStream createCOSStream(COSDictionary dictionary, long startPosition,
-            long streamLength)
-    {
-        COSStream stream = new COSStream(scratchFile,
-                parser.createRandomAccessReadView(startPosition, streamLength));
-        dictionary.forEach(stream::setItem);
-        return stream;
-    }
     /**
      * Get the dictionary containing the linearization information if the pdf is linearized.
      * 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSInputStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSInputStream.java?rev=1877825&r1=1877824&r2=1877825&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSInputStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSInputStream.java Sat May 16 17:20:09 2020
@@ -77,8 +77,7 @@ public final class COSInputStream extend
                 {
                     // scratch file
                     final RandomAccess buffer = scratchFile.createBuffer();
-                    DecodeResult result = filters.get(i).decode(input,
-                            new RandomAccessOutputStream(buffer), parameters, i, options);
+                    DecodeResult result = filters.get(i).decode(input, new RandomAccessOutputStream(buffer), parameters, i, options);
                     results.add(result);
                     input = new RandomAccessInputStream(buffer)
                     {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java?rev=1877825&r1=1877824&r2=1877825&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java Sat May 16 17:20:09 2020
@@ -37,7 +37,6 @@ import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.RandomAccess;
 import org.apache.pdfbox.io.RandomAccessInputStream;
 import org.apache.pdfbox.io.RandomAccessOutputStream;
-import org.apache.pdfbox.io.RandomAccessReadView;
 import org.apache.pdfbox.io.ScratchFile;
 
 /**
@@ -47,15 +46,10 @@ import org.apache.pdfbox.io.ScratchFile;
  */
 public class COSStream extends COSDictionary implements Closeable
 {
-    // backing store, in-memory or on-disk
-    private RandomAccess randomAccess;
-    // used as a temp buffer during decoding
-    private final ScratchFile scratchFile;
-    // true if there's an open OutputStream
-    private boolean isWriting;
+    private RandomAccess randomAccess;      // backing store, in-memory or on-disk
+    private final ScratchFile scratchFile;  // used as a temp buffer during decoding
+    private boolean isWriting;              // true if there's an open OutputStream
     
-    private RandomAccessReadView randomAccessReadView;
-
     private static final Log LOG = LogFactory.getLog(COSStream.class);
     
     /**
@@ -83,26 +77,6 @@ public class COSStream extends COSDictio
     }
 
     /**
-     * Creates a new stream with an empty dictionary. Data is stored in the given scratch file.
-     *
-     * @param scratchFile Scratch file for writing stream data.
-     */
-    public COSStream(ScratchFile scratchFile, RandomAccessReadView randomAccessReadView)
-    {
-        this(scratchFile);
-        this.randomAccessReadView = randomAccessReadView;
-        try
-        {
-            setInt(COSName.LENGTH, (int) randomAccessReadView.length());
-        }
-        catch (IOException e)
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override
@@ -210,16 +184,8 @@ public class COSStream extends COSDictio
         {
             throw new IllegalStateException("Cannot read while there is an open stream writer");
         }
-        if (randomAccess == null && randomAccessReadView != null)
-        {
-            randomAccessReadView.seek(0);
-            return new RandomAccessInputStream(randomAccessReadView);
-        }
-        else
-        {
-            ensureRandomAccessExists(true);
-            return new RandomAccessInputStream(randomAccess);
-        }
+        ensureRandomAccessExists(true);
+        return new RandomAccessInputStream(randomAccess);
     }
 
     /**
@@ -235,7 +201,13 @@ public class COSStream extends COSDictio
 
     public COSInputStream createInputStream(DecodeOptions options) throws IOException
     {
-        InputStream input = createRawInputStream();
+        checkClosed();
+        if (isWriting)
+        {
+            throw new IllegalStateException("Cannot read while there is an open stream writer");
+        }
+        ensureRandomAccessExists(true);
+        InputStream input = new RandomAccessInputStream(randomAccess);
         return COSInputStream.create(getFilterList(), this, input, scratchFile, options);
     }
 
@@ -269,10 +241,8 @@ public class COSStream extends COSDictio
         {
             setItem(COSName.FILTER, filters);
         }
-        if (randomAccess != null)
-            randomAccess.clear();
-        else
-            randomAccess = scratchFile.createBuffer();
+        IOUtils.closeQuietly(randomAccess);
+        randomAccess = scratchFile.createBuffer();
         OutputStream randomOut = new RandomAccessOutputStream(randomAccess);
         OutputStream cosOut = new COSOutputStream(getFilterList(), this, randomOut, scratchFile);
         isWriting = true;
@@ -307,10 +277,8 @@ public class COSStream extends COSDictio
         {
             throw new IllegalStateException("Cannot have more than one open stream writer.");
         }
-        if (randomAccess != null)
-            randomAccess.clear();
-        else
-            randomAccess = scratchFile.createBuffer();
+        IOUtils.closeQuietly(randomAccess);
+        randomAccess = scratchFile.createBuffer();
         OutputStream out = new RandomAccessOutputStream(randomAccess);
         isWriting = true;
         return new FilterOutputStream(out)
@@ -357,7 +325,7 @@ public class COSStream extends COSDictio
     /**
      * Returns the length of the encoded stream.
      *
-     * @return length in bytesg
+     * @return length in bytes
      */
     public long getLength()
     {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java?rev=1877825&r1=1877824&r2=1877825&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSParser.java Sat May 16 17:20:09 2020
@@ -18,8 +18,6 @@ package org.apache.pdfbox.cos;
 
 import java.io.IOException;
 
-import org.apache.pdfbox.io.RandomAccessReadView;
-
 public interface ICOSParser
 {
 
@@ -34,6 +32,4 @@ public interface ICOSParser
      */
     public COSBase dereferenceCOSObject(COSObject obj) throws IOException;
 
-    public RandomAccessReadView createRandomAccessReadView(long startPosition, long streamLength);
-
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1877825&r1=1877824&r2=1877825&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java Sat May 16 17:20:09 2020
@@ -18,6 +18,7 @@ package org.apache.pdfbox.pdfparser;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.nio.charset.StandardCharsets;
 import java.security.GeneralSecurityException;
 import java.security.KeyStore;
@@ -44,7 +45,6 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.cos.ICOSParser;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.RandomAccessRead;
-import org.apache.pdfbox.io.RandomAccessReadView;
 import org.apache.pdfbox.pdfparser.XrefTrailerResolver.XRefType;
 import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
 import org.apache.pdfbox.pdmodel.encryption.DecryptionMaterial;
@@ -573,12 +573,6 @@ public class COSParser extends BaseParse
         return parsedObj;
     }
 
-    @Override
-    public RandomAccessReadView createRandomAccessReadView(long startPosition, long streamLength)
-    {
-        return new RandomAccessReadView(source, startPosition, streamLength);
-    }
-
     /**
      * Parse the object for the given object number.  
      * 
@@ -810,6 +804,9 @@ public class COSParser extends BaseParse
                 "Wrong type of length object: " + lengthBaseObj.getClass().getSimpleName());
     }
     
+    private static final int STREAMCOPYBUFLEN = 8192;
+    private final byte[] streamCopyBuf = new byte[STREAMCOPYBUFLEN];
+
     /**
      * This will read a COSStream from the input stream using length attribute within dictionary. If
      * length attribute is a indirect reference it is first resolved to get the stream length. This
@@ -826,6 +823,8 @@ public class COSParser extends BaseParse
      */
     protected COSStream parseCOSStream(COSDictionary dic) throws IOException
     {
+        COSStream stream = document.createCOSStream(dic);
+       
         // read 'stream'; this was already tested in parseObjectsDynamically()
         readString(); 
         
@@ -848,23 +847,18 @@ public class COSParser extends BaseParse
             }
         }
 
-        COSStream stream = null;
-        long streamStartPosition = source.getPosition();
-        if (streamLengthObj != null && validateStreamLength(streamLengthObj.longValue()))
-        {
-            stream = document.createCOSStream(dic, streamStartPosition,
-                    streamLengthObj.longValue());
-            // skip stream
-            source.seek(source.getPosition() + streamLengthObj.intValue());
-        }
-        else
+        // get output stream to copy data to
+        try (OutputStream out = stream.createRawOutputStream())
         {
-            // get output stream to copy data to
-            long streamLength = readUntilEndStream(new EndstreamOutputStream());
-            stream = document.createCOSStream(dic, streamStartPosition,
-                    streamLength);
+            if (streamLengthObj != null && validateStreamLength(streamLengthObj.longValue()))
+            {
+                readValidStream(out, streamLengthObj);
+            }
+            else
+            {
+                readUntilEndStream(new EndstreamOutputStream(out));
+            }
         }
-
         String endStream = readString();
         if (endStream.equals("endobj") && isLenient)
         {
@@ -886,49 +880,53 @@ public class COSParser extends BaseParse
                     "Error reading stream, expected='endstream' actual='"
                     + endStream + "' at offset " + source.getPosition());
         }
+
         return stream;
     }
 
     /**
-     * This method will read through the current stream object until we find the keyword "endstream" meaning we're at the
-     * end of this object. Some pdf files, however, forget to write some endstream tags and just close off objects with an
-     * "endobj" tag so we have to handle this case as well.
+     * This method will read through the current stream object until
+     * we find the keyword "endstream" meaning we're at the end of this
+     * object. Some pdf files, however, forget to write some endstream tags
+     * and just close off objects with an "endobj" tag so we have to handle
+     * this case as well.
      * 
-     * This method is optimized using buffered IO and reduced number of byte compare operations.
+     * This method is optimized using buffered IO and reduced number of
+     * byte compare operations.
      * 
-     * @param out stream we write out to.
+     * @param out  stream we write out to.
      * 
      * @throws IOException if something went wrong
      */
-    private long readUntilEndStream(final EndstreamOutputStream out) throws IOException
+    private void readUntilEndStream( final OutputStream out ) throws IOException
     {
         int bufSize;
         int charMatchCount = 0;
         byte[] keyw = ENDSTREAM;
-
+        
         // last character position of shortest keyword ('endobj')
         final int quickTestOffset = 5;
-
+        
         // read next chunk into buffer; already matched chars are added to beginning of buffer
-        while ((bufSize = source.read(strmBuf, charMatchCount, STRMBUFLEN - charMatchCount)) > 0)
+        while ( ( bufSize = source.read( strmBuf, charMatchCount, STRMBUFLEN - charMatchCount ) ) > 0 ) 
         {
             bufSize += charMatchCount;
-
+            
             int bIdx = charMatchCount;
             int quickTestIdx;
-
+        
             // iterate over buffer, trying to find keyword match
-            for (int maxQuicktestIdx = bufSize - quickTestOffset; bIdx < bufSize; bIdx++)
+            for ( int maxQuicktestIdx = bufSize - quickTestOffset; bIdx < bufSize; bIdx++ ) 
             {
                 // reduce compare operations by first test last character we would have to
                 // match if current one matches; if it is not a character from keywords
-                // we can move behind the test character; this shortcut is inspired by the
+                // we can move behind the test character; this shortcut is inspired by the 
                 // Boyer-Moore string search algorithm and can reduce parsing time by approx. 20%
                 quickTestIdx = bIdx + quickTestOffset;
                 if (charMatchCount == 0 && quickTestIdx < maxQuicktestIdx)
-                {
+                {                    
                     final byte ch = strmBuf[quickTestIdx];
-                    if ((ch > 't') || (ch < 'a'))
+                    if ( ( ch > 't' ) || ( ch < 'a' ) ) 
                     {
                         // last character we would have to match if current character would match
                         // is not a character from keywords -> jump behind and start over
@@ -936,64 +934,80 @@ public class COSParser extends BaseParse
                         continue;
                     }
                 }
-
+                
                 // could be negative - but we only compare to ASCII
                 final byte ch = strmBuf[bIdx];
-
-                if (ch == keyw[charMatchCount])
+            
+                if ( ch == keyw[ charMatchCount ] ) 
                 {
-                    if (++charMatchCount == keyw.length)
+                    if ( ++charMatchCount == keyw.length ) 
                     {
                         // match found
                         bIdx++;
                         break;
                     }
-                }
-                else
+                } 
+                else 
                 {
-                    if ((charMatchCount == 3) && (ch == ENDOBJ[charMatchCount]))
+                    if ( ( charMatchCount == 3 ) && ( ch == ENDOBJ[ charMatchCount ] ) ) 
                     {
                         // maybe ENDSTREAM is missing but we could have ENDOBJ
                         keyw = ENDOBJ;
                         charMatchCount++;
-                    }
-                    else
+                    } 
+                    else 
                     {
-                        // no match; incrementing match start by 1 would be dumb since we already know
-                        // matched chars depending on current char read we may already have beginning
-                        // of a new match: 'e': first char matched; 'n': if we are at match position
-                        // idx 7 we already read 'e' thus 2 chars matched for each other char we have
+                        // no match; incrementing match start by 1 would be dumb since we already know 
+                        // matched chars depending on current char read we may already have beginning 
+                        // of a new match: 'e': first char matched; 'n': if we are at match position 
+                        // idx 7 we already read 'e' thus 2 chars matched for each other char we have 
                         // to start matching first keyword char beginning with next read position
-                        charMatchCount = (ch == E) ? 1
-                                : ((ch == N) && (charMatchCount == 7)) ? 2 : 0;
+                        charMatchCount = ( ch == E ) ? 1 : ( ( ch == N ) && ( charMatchCount == 7 ) ) ? 2 : 0;
                         // search again for 'endstream'
                         keyw = ENDSTREAM;
                     }
-                }
+                } 
             }
-
-            int contentBytes = Math.max(0, bIdx - charMatchCount);
-
+            
+            int contentBytes = Math.max( 0, bIdx - charMatchCount );
+            
             // write buffer content until first matched char to output stream
-            if (contentBytes > 0)
+            if ( contentBytes > 0 )
             {
-                out.write(strmBuf, 0, contentBytes);
+                out.write( strmBuf, 0, contentBytes );
             }
-            if (charMatchCount == keyw.length)
+            if ( charMatchCount == keyw.length ) 
             {
                 // keyword matched; unread matched keyword (endstream/endobj) and following buffered content
-                source.rewind(bufSize - contentBytes);
+                source.rewind( bufSize - contentBytes );
                 break;
-            }
-            else
+            } 
+            else 
             {
                 // copy matched chars at start of buffer
-                System.arraycopy(keyw, 0, strmBuf, 0, charMatchCount);
-            }
+                System.arraycopy( keyw, 0, strmBuf, 0, charMatchCount );
+            }            
         }
         // this writes a lonely CR or drops trailing CR LF and LF
         out.flush();
-        return out.getLength();
+    }
+
+    private void readValidStream(OutputStream out, COSNumber streamLengthObj) throws IOException
+    {
+        long remainBytes = streamLengthObj.longValue();
+        while (remainBytes > 0)
+        {
+            final int chunk = (remainBytes > STREAMCOPYBUFLEN) ? STREAMCOPYBUFLEN : (int) remainBytes;
+            final int readBytes = source.read(streamCopyBuf, 0, chunk);
+            if (readBytes <= 0)
+            {
+                // shouldn't happen, the stream length has already been validated
+                throw new IOException("read error at offset " + source.getPosition()
+                        + ": expected " + chunk + " bytes, but read() returns " + readBytes);
+            }
+            out.write(streamCopyBuf, 0, readBytes);
+            remainBytes -= readBytes;
+        }
     }
 
     private boolean validateStreamLength(long streamLength) throws IOException

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/EndstreamOutputStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/EndstreamOutputStream.java?rev=1877825&r1=1877824&r2=1877825&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/EndstreamOutputStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/EndstreamOutputStream.java Sat May 16 17:20:09 2020
@@ -16,7 +16,7 @@
 
 package org.apache.pdfbox.pdfparser;
 
-import java.io.FilterOutputStream;
+import java.io.BufferedOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 
@@ -30,23 +30,20 @@ import java.io.OutputStream;
  *
  * @author Tilman Hausherr
  */
-class EndstreamOutputStream extends FilterOutputStream
+class EndstreamOutputStream extends BufferedOutputStream
 {
+    //TODO: replace this class with a PullBackOutputStream class if there ever is one
+    
     private boolean hasCR = false;
     private boolean hasLF = false;
     private int pos = 0;
     private boolean mustFilter = true;
-    private long length = 0;
 
     EndstreamOutputStream(OutputStream out)
     {
         super(out);
     }
 
-    public EndstreamOutputStream()
-    {
-        super(null);
-    }
     /**
      * Write CR and/or LF that were kept, then writes len bytes from the 
      * specified byte array starting at offset off to this output stream,
@@ -89,11 +86,11 @@ class EndstreamOutputStream extends Filt
                     // reset hasCR done too to avoid CR getting written in the flush
                     return;
                 }
-                length++;
+                super.write('\r');               
             }
             if (hasLF)
             {
-                length++;
+                super.write('\n');
                 hasLF = false;
             }
             // don't write CR, LF, or CR LF if at the end of the buffer
@@ -116,7 +113,7 @@ class EndstreamOutputStream extends Filt
                 }
             }
         }
-        length += len;
+        super.write(b, off, len);
         pos += len;
     }
 
@@ -132,15 +129,11 @@ class EndstreamOutputStream extends Filt
         // if there is only a CR and no LF, write it
         if (hasCR && !hasLF)
         {
-            length++;
+            super.write('\r');
             ++pos;
         }
         hasCR = false;
         hasLF = false;
-    }
-
-    public long getLength()
-    {
-        return length;
+        super.flush();
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java?rev=1877825&r1=1877824&r2=1877825&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/SignatureOptions.java Sat May 16 17:20:09 2020
@@ -23,7 +23,7 @@ import java.io.InputStream;
 
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.io.RandomAccessBuffer;
-import org.apache.pdfbox.io.RandomAccessBufferedFile;
+import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
 import org.apache.pdfbox.io.RandomAccessRead;
 import org.apache.pdfbox.pdfparser.PDFParser;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDVisibleSigProperties;
@@ -79,7 +79,7 @@ public class SignatureOptions implements
      */
     public void setVisualSignature(File file) throws IOException
     {
-        initFromRandomAccessRead(new RandomAccessBufferedFile(file));
+        initFromRandomAccessRead(new RandomAccessBufferedFileInputStream(file));
     }
 
     /**