You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2019/08/08 16:31:16 UTC
[commons-compress] branch master updated: COMPRESS-490 add unit
tests, thanks to Alex Rebert
This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push:
new 6635661 COMPRESS-490 add unit tests, thanks to Alex Rebert
6635661 is described below
commit 66356617415d2642a50ebd0c73f376fa621ab87d
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Thu Aug 8 18:30:44 2019 +0200
COMPRESS-490 add unit tests, thanks to Alex Rebert
---
.../lz4/FramedLZ4CompressorInputStreamTest.java | 29 +++++++++++++++++++++
.../resources/COMPRESS-490/ArithmeticException.lz4 | Bin 0 -> 29 bytes
.../ArrayIndexOutOfBoundsException1.lz4 | 1 +
.../ArrayIndexOutOfBoundsException2.lz4 | Bin 0 -> 405 bytes
4 files changed, 30 insertions(+)
diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java
index a57c007..82e5075 100644
--- a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStreamTest.java
@@ -32,11 +32,16 @@ import java.util.Arrays;
import org.apache.commons.compress.AbstractTestCase;
import org.apache.commons.compress.compressors.CompressorStreamFactory;
import org.apache.commons.compress.utils.IOUtils;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public final class FramedLZ4CompressorInputStreamTest
extends AbstractTestCase {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Test
public void testMatches() throws IOException {
assertFalse(FramedLZ4CompressorInputStream.matches(new byte[10], 4));
@@ -619,6 +624,21 @@ public final class FramedLZ4CompressorInputStreamTest
}
}
+ @Test
+ public void backreferenceOfSize0CausesIOException() throws IOException {
+ expectIOException("COMPRESS-490/ArithmeticException.lz4");
+ }
+
+ @Test
+ public void backreferenceAtStartCausesIOException() throws IOException {
+ expectIOException("COMPRESS-490/ArrayIndexOutOfBoundsException1.lz4");
+ }
+
+ @Test
+ public void backreferenceWithOffsetTooBigCausesIOException() throws IOException {
+ expectIOException("COMPRESS-490/ArrayIndexOutOfBoundsException2.lz4");
+ }
+
interface StreamWrapper {
InputStream wrap(InputStream in) throws Exception;
}
@@ -642,4 +662,13 @@ public final class FramedLZ4CompressorInputStreamTest
System.arraycopy(from, 0, to, from.length, from.length);
return to;
}
+
+ private void expectIOException(String fileName) throws IOException {
+ thrown.expect(IOException.class);
+ try (InputStream is = new FileInputStream(getFile(fileName))) {
+ final FramedLZ4CompressorInputStream in = new FramedLZ4CompressorInputStream(is);
+ IOUtils.toByteArray(in);
+ }
+ }
+
}
diff --git a/src/test/resources/COMPRESS-490/ArithmeticException.lz4 b/src/test/resources/COMPRESS-490/ArithmeticException.lz4
new file mode 100644
index 0000000..6e11a81
Binary files /dev/null and b/src/test/resources/COMPRESS-490/ArithmeticException.lz4 differ
diff --git a/src/test/resources/COMPRESS-490/ArrayIndexOutOfBoundsException1.lz4 b/src/test/resources/COMPRESS-490/ArrayIndexOutOfBoundsException1.lz4
new file mode 100644
index 0000000..7bbe4d8
--- /dev/null
+++ b/src/test/resources/COMPRESS-490/ArrayIndexOutOfBoundsException1.lz4
@@ -0,0 +1 @@
+"Md@�0000000000
\ No newline at end of file
diff --git a/src/test/resources/COMPRESS-490/ArrayIndexOutOfBoundsException2.lz4 b/src/test/resources/COMPRESS-490/ArrayIndexOutOfBoundsException2.lz4
new file mode 100644
index 0000000..e37c3a8
Binary files /dev/null and b/src/test/resources/COMPRESS-490/ArrayIndexOutOfBoundsException2.lz4 differ