poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1819772 - in /poi/trunk/src: java/org/apache/poi/util/LittleEndianByteArrayInputStream.java testcases/org/apache/poi/util/TestLittleEndianStreams.java
Date Mon, 01 Jan 2018 14:39:26 GMT
Author: centic
Date: Mon Jan  1 14:39:26 2018
New Revision: 1819772

URL: http://svn.apache.org/viewvc?rev=1819772&view=rev
Log:
Bug 61550: Add more information to exception text and verify that it is thrown

Modified:
    poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
    poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java

Modified: poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java?rev=1819772&r1=1819771&r2=1819772&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java Mon Jan 
1 14:39:26 2018
@@ -37,7 +37,8 @@ public class LittleEndianByteArrayInputS
 
 	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);
 		}
 	}
 

Modified: poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java?rev=1819772&r1=1819771&r2=1819772&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java Mon Jan  1 14:39:26
2018
@@ -81,4 +81,20 @@ public final class TestLittleEndianStrea
 		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"));
+		}
+	}
 }



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


Mime
View raw message