aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2018-01-01 14:39:26 +0000
committerDominik Stadler <centic@apache.org>2018-01-01 14:39:26 +0000
commit7e04bd33e5eda1c7fb2bd4478a4a1fd745351480 (patch)
tree3988db7e5f5e587b0ac703ea3706bb0b42ef983d
parent8507286f77bdb3942714f98e4c191823040a39d0 (diff)
downloadpoi-7e04bd33e5eda1c7fb2bd4478a4a1fd745351480.tar.gz
poi-7e04bd33e5eda1c7fb2bd4478a4a1fd745351480.zip
Bug 61550: Add more information to exception text and verify that it is thrown
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1819772 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java3
-rw-r--r--src/testcases/org/apache/poi/util/TestLittleEndianStreams.java16
2 files changed, 18 insertions, 1 deletions
diff --git a/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java b/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
index ff88e7164a..fcb44f653e 100644
--- a/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
+++ b/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
@@ -37,7 +37,8 @@ public class LittleEndianByteArrayInputStream extends ByteArrayInputStream imple
protected void checkPosition(int i) {
if (i > count - pos) {
- throw new RuntimeException("Buffer overrun");
+ throw new RuntimeException("Buffer overrun, having " + count + " bytes in the stream and position is at " + pos +
+ ", but trying to increment position by " + i);
}
}
diff --git a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
index c05e365a92..1b327669ae 100644
--- a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
+++ b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
@@ -81,4 +81,20 @@ public final class TestLittleEndianStreams extends TestCase {
assertEquals(0x33, lei.readUByte());
assertEquals(0, lei.available());
}
+
+ public void testBufferOverrun() {
+ byte[] srcBuf = HexRead.readFromString("99 88 77");
+ LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf);
+
+ // do initial read to increment the read index beyond zero
+ assertEquals(0x8899, lei.readUShort());
+
+ // only one byte left, so this should fail
+ try {
+ lei.readFully(new byte[4]);
+ fail("Should catch exception here");
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().contains("Buffer overrun"));
+ }
+ }
}