poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From talli...@apache.org
Subject svn commit: r1857277 - in /poi/trunk/src: java/org/apache/poi/poifs/filesystem/ java/org/apache/poi/poifs/macros/ java/org/apache/poi/util/ ooxml/java/org/apache/poi/openxml4j/util/ ooxml/java/org/apache/poi/xssf/binary/ scratchpad/src/org/apache/poi/h...
Date Wed, 10 Apr 2019 19:11:02 GMT
Author: tallison
Date: Wed Apr 10 19:11:02 2019
New Revision: 1857277

URL: http://svn.apache.org/viewvc?rev=1857277&view=rev
Log:
Bug 63330 -- use skipfully instead of hoping skip() works

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java
    poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
    poi/trunk/src/java/org/apache/poi/util/BoundedInputStream.java
    poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java
    poi/trunk/src/java/org/apache/poi/util/RLEDecompressingInputStream.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipArchiveThresholdInputStream.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBParser.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java Wed Apr 10
19:11:02 2019
@@ -36,6 +36,11 @@ import org.apache.poi.util.LittleEndianI
  * {@link POIFSFileSystem} instance.
  */
 public final class DocumentInputStream extends InputStream implements LittleEndianInput {
+
+    private static int SKIP_BUFFER_SIZE = 2048;
+
+    private static byte[] SKIP_BYTE_BUFFER = new byte[SKIP_BUFFER_SIZE];
+
     /** returned by read operations if we're at end of document */
     private static final int EOF = -1;
 

Modified: poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java Wed Apr 10 19:11:02
2019
@@ -260,10 +260,7 @@ public class VBAMacroReader implements C
             InputStream compressed = new DocumentInputStream(documentNode);
             try {
                 // we know the offset already, so decompress immediately on-the-fly
-                long skippedBytes = compressed.skip(module.offset);
-                if (skippedBytes != module.offset) {
-                    throw new IOException("tried to skip " + module.offset + " bytes, but
actually skipped " + skippedBytes + " bytes");
-                }
+                trySkip(compressed, module.offset);
                 decompressed = new RLEDecompressingInputStream(compressed);
                 module.read(decompressed);
                 return;

Modified: poi/trunk/src/java/org/apache/poi/util/BoundedInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/BoundedInputStream.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/BoundedInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/BoundedInputStream.java Wed Apr 10 19:11:02 2019
@@ -131,13 +131,13 @@ public class BoundedInputStream extends
     /**
      * Invokes the delegate's <code>skip(long)</code> method.
      * @param n the number of bytes to skip
-     * @return the actual number of bytes skipped
+     * @return the actual number of bytes skipped; might be fewer than requested
      * @throws IOException if an I/O error occurs
      */
     @Override
     public long skip(long n) throws IOException {
         long toSkip = max>=0 ? Math.min(n, max-pos) : n;
-        long skippedBytes = in.skip(toSkip);
+        long skippedBytes = IOUtils.skipFully(in, toSkip);
         pos+=skippedBytes;
         return skippedBytes;
     }

Modified: poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java Wed Apr 10 19:11:02
2019
@@ -204,6 +204,10 @@ public class LittleEndianInputStream ext
 
 
 	public void skipFully(int len) throws IOException {
-		IOUtils.skipFully(this, len);
+		long skipped = IOUtils.skipFully(this, len);
+		if (skipped > Integer.MAX_VALUE) {
+			throw new IOException("can't skip further than "+Integer.MAX_VALUE);
+		}
+		checkEOF((int)skipped, len);
 	}
 }

Modified: poi/trunk/src/java/org/apache/poi/util/RLEDecompressingInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/RLEDecompressingInputStream.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/RLEDecompressingInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/RLEDecompressingInputStream.java Wed Apr 10 19:11:02
2019
@@ -123,6 +123,7 @@ public class RLEDecompressingInputStream
 
     @Override
     public long skip(long n) throws IOException {
+        //this relies on readChunk's readFully to skipFully
         long length = n;
         while (length > 0) {
             if (pos >= len) {
@@ -165,7 +166,7 @@ public class RLEDecompressingInputStream
         }
         boolean rawChunk = (w & 0x8000) == 0;
         if (rawChunk) {
-            if (in.read(buf, 0, chunkSize) < chunkSize) {
+            if (IOUtils.readFully(in, buf, 0, chunkSize) < chunkSize) {
                 throw new IllegalStateException(String.format(Locale.ROOT, "Not enough bytes
read, expected %d", chunkSize));
             }
             return chunkSize;

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipArchiveThresholdInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipArchiveThresholdInputStream.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipArchiveThresholdInputStream.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipArchiveThresholdInputStream.java
Wed Apr 10 19:11:02 2019
@@ -31,6 +31,7 @@ import org.apache.commons.compress.archi
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.commons.compress.utils.InputStreamStatistics;
 import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.Internal;
 
 @Internal
@@ -85,7 +86,7 @@ public class ZipArchiveThresholdInputStr
 
     @Override
     public long skip(long n) throws IOException {
-        long cnt = super.skip(n);
+        long cnt = IOUtils.skipFully(super.in, n);
         if (cnt > 0) {
             checkThreshold();
         }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBParser.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBParser.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBParser.java Wed Apr 10 19:11:02
2019
@@ -96,7 +96,7 @@ public abstract class XSSFBParser {
             is.readFully(buff);
             handleRecord(recordId, buff);
         } else {
-            long length = is.skip(recordLength);
+            long length = IOUtils.skipFully(is, recordLength);
             if (length != recordLength) {
                 throw new XSSFBParseException("End of file reached before expected.\t"+
                 "Tried to skip "+recordLength + ", but only skipped "+length);

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfFont.java Wed Apr 10 19:11:02
2019
@@ -19,12 +19,10 @@ package org.apache.poi.hemf.record.emf;
 
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
 
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.common.usermodel.fonts.FontCharset;
 import org.apache.poi.hwmf.record.HwmfFont;
-import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndianConsts;
 import org.apache.poi.util.LittleEndianInputStream;
 
@@ -418,7 +416,10 @@ public class HemfFont extends HwmfFont {
             logPan.xHeight = LogFontPanose.XHeight.values()[leis.readUByte()];
 
             // skip 2 byte to ensure 32-bit alignment of this structure.
-            leis.skip(2);
+            long skipped = IOUtils.skipFully(leis,2);
+            if (skipped != 2) {
+                throw new IOException("Didn't skip 2: "+skipped);
+            }
 
             size += 6*LittleEndianConsts.INT_SIZE+10* LittleEndianConsts.BYTE_SIZE+2;
         } else {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/EMF.java Wed Apr 10 19:11:02 2019
@@ -26,6 +26,7 @@ import java.util.zip.InflaterInputStream
 
 import org.apache.poi.hslf.exceptions.HSLFException;
 import org.apache.poi.sl.image.ImageHeaderEMF;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.Units;
 
 /**
@@ -42,7 +43,7 @@ public final class EMF extends Metafile
             InputStream is = new ByteArrayInputStream( rawdata );
             Header header = new Header();
             header.read(rawdata, CHECKSUM_SIZE);
-            long len = is.skip(header.getSize() + (long)CHECKSUM_SIZE);
+            long len = IOUtils.skipFully(is,header.getSize() + (long)CHECKSUM_SIZE);
             assert(len == header.getSize() + CHECKSUM_SIZE);
 
             InflaterInputStream inflater = new InflaterInputStream( is );

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java Wed Apr 10 19:11:02 2019
@@ -26,6 +26,7 @@ import java.util.zip.InflaterInputStream
 
 import org.apache.poi.hslf.exceptions.HSLFException;
 import org.apache.poi.sl.image.ImageHeaderPICT;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.util.Units;
@@ -58,7 +59,7 @@ public final class PICT extends Metafile
         Header header = new Header();
         header.read(data, pos);
         long bs_exp = (long)pos + header.getSize();
-        long bs_act = bis.skip(bs_exp);
+        long bs_act = IOUtils.skipFully(bis, bs_exp);
         if (bs_exp != bs_act) {
             throw new EOFException();
         }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java?rev=1857277&r1=1857276&r2=1857277&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/blip/WMF.java Wed Apr 10 19:11:02 2019
@@ -26,6 +26,7 @@ import java.util.zip.InflaterInputStream
 
 import org.apache.poi.hslf.exceptions.HSLFException;
 import org.apache.poi.sl.image.ImageHeaderWMF;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.Units;
 
 /**
@@ -42,8 +43,9 @@ public final class WMF extends Metafile
             InputStream is = new ByteArrayInputStream( rawdata );
             Header header = new Header();
             header.read(rawdata, CHECKSUM_SIZE*getUIDInstanceCount());
-            long len = is.skip(header.getSize() + (long)CHECKSUM_SIZE*getUIDInstanceCount());
-            assert(len == header.getSize() + CHECKSUM_SIZE*getUIDInstanceCount());
+            long skipLen = header.getSize() + CHECKSUM_SIZE*getUIDInstanceCount();
+            long skipped = IOUtils.skipFully(is, skipLen);
+            assert(skipped == skipLen);
 
             ImageHeaderWMF aldus = new ImageHeaderWMF(header.getBounds());
             aldus.write(out);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message