pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1863581 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java
Date Mon, 22 Jul 2019 16:53:14 GMT
Author: tilman
Date: Mon Jul 22 16:53:14 2019
New Revision: 1863581

URL: http://svn.apache.org/viewvc?rev=1863581&view=rev
Log:
PDFBOX-4601: include more debug logging; clarify comment; add workaround for possible AWS
lambda bug suggested by Timo Boehme

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java?rev=1863581&r1=1863580&r2=1863581&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java Mon Jul
22 16:53:14 2019
@@ -234,18 +234,29 @@ public class ScratchFile implements Clos
                 
                 if (expectedFileLen != fileLen)
                 {
-                    throw new IOException("Expected scratch file size of " + expectedFileLen
+ " but found " + fileLen);
+                    throw new IOException("Expected scratch file size of " + expectedFileLen
+
+                                          " but found " + fileLen + " in file " + file);
                 }
                     
-                // enlarge if we do not overflow
+                // enlarge if we do not int overflow
                 if (pageCount + ENLARGE_PAGE_COUNT > pageCount)
                 {
-                    LOG.debug("fileLen before: " + fileLen + ", raf length: " + raf.length());
-                    LOG.debug("file: " + file + ", length: " + file.length());
+                    LOG.debug("file: " + file);
+                    LOG.debug("fileLen before: " + fileLen + ", raf length: " + raf.length()
+ ", file length: " + file.length());
                     fileLen += ENLARGE_PAGE_COUNT * PAGE_SIZE;
 
                     raf.setLength(fileLen);
-                    LOG.debug("fileLen after:  " + fileLen + ", raf length: " + raf.length());
+                    LOG.debug("fileLen after1:  " + fileLen + ", raf length: " + raf.length()
+ ", file length: " + file.length());
+                    if (fileLen != raf.length() || fileLen != file.length())
+                    {
+                        // PDFBOX-4601 possible AWS lambda bug that setLength() doesn't throw
+                        // if not enough space
+                        long origFilePointer = raf.getFilePointer();
+                        raf.seek(fileLen - 1);
+                        raf.write(0);
+                        raf.seek(origFilePointer);
+                        LOG.debug("fileLen after2:  " + fileLen + ", raf length: " + raf.length()
+ ", file length: " + file.length());
+                    }
                     freePages.set(pageCount, pageCount + ENLARGE_PAGE_COUNT);
                 }
             }



Mime
View raw message