aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2015-07-20 14:03:35 +0000
committerDominik Stadler <centic@apache.org>2015-07-20 14:03:35 +0000
commitdbdbb0cfe693f8a55aff7f287fc4b7ba071c6e56 (patch)
treec5590ee35e758e7a57facbe27d2bce57414f0406 /src/java/org/apache/poi
parentee3925aff1996f68442ae366feff4cd30d525c21 (diff)
downloadpoi-dbdbb0cfe693f8a55aff7f287fc4b7ba071c6e56.tar.gz
poi-dbdbb0cfe693f8a55aff7f287fc4b7ba071c6e56.zip
Bug 58156: Possible data corruption in hasPOIFSHeader and hasOOXMLHeader
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691948 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r--src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java10
-rw-r--r--src/java/org/apache/poi/util/IOUtils.java2
2 files changed, 8 insertions, 4 deletions
diff --git a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
index c27ba3cd14..9817c3d818 100644
--- a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
+++ b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
@@ -354,7 +354,11 @@ public class NPOIFSFileSystem extends BlockStore
* has a POIFS (OLE2) header at the start of it.
* If your InputStream does not support mark / reset,
* then wrap it in a PushBackInputStream, then be
- * sure to always use that, and not the original!
+ * sure to always use that and not the original!
+ *
+ * After the method call, the InputStream is at the
+ * same position as of the time of entering the method.
+ *
* @param inp An InputStream which supports either mark/reset, or is a PushbackInputStream
*/
public static boolean hasPOIFSHeader(InputStream inp) throws IOException {
@@ -362,13 +366,13 @@ public class NPOIFSFileSystem extends BlockStore
inp.mark(8);
byte[] header = new byte[8];
- IOUtils.readFully(inp, header);
+ int bytesRead = IOUtils.readFully(inp, header);
LongField signature = new LongField(HeaderBlockConstants._signature_offset, header);
// Wind back those 8 bytes
if(inp instanceof PushbackInputStream) {
PushbackInputStream pin = (PushbackInputStream)inp;
- pin.unread(header);
+ pin.unread(header, 0, bytesRead);
} else {
inp.reset();
}
diff --git a/src/java/org/apache/poi/util/IOUtils.java b/src/java/org/apache/poi/util/IOUtils.java
index f1d5a2378d..b5f22a1a1a 100644
--- a/src/java/org/apache/poi/util/IOUtils.java
+++ b/src/java/org/apache/poi/util/IOUtils.java
@@ -57,7 +57,7 @@ public final class IOUtils {
// Wind back those 8 bytes
if(stream instanceof PushbackInputStream) {
PushbackInputStream pin = (PushbackInputStream)stream;
- pin.unread(header);
+ pin.unread(header, 0, read);
} else {
stream.reset();
}