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 2018/01/09 17:41:15 UTC

[22/28] commons-compress git commit: COMPRESS-380 ensure reading of stored block stats at byte boundary

COMPRESS-380 ensure reading of stored block stats at byte boundary


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/2d25368d
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/2d25368d
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/2d25368d

Branch: refs/heads/master
Commit: 2d25368dd82e50dd68cf0d256084881e6a3153d9
Parents: 77a0a69
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Jan 8 07:32:17 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Jan 8 07:32:17 2018 +0100

----------------------------------------------------------------------
 .../compress/compressors/deflate64/HuffmanDecoder.java   |  2 +-
 .../apache/commons/compress/utils/BitInputStream.java    | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/2d25368d/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
index 9d6585a..5ed4079 100644
--- a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
+++ b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
@@ -134,7 +134,7 @@ class HuffmanDecoder implements Closeable {
                     int mode = (int) readBits(2);
                     switch (mode) {
                         case 0:
-                            readBits(Byte.SIZE - 3);
+                            reader.alignWithByteBoundary();
                             long bLen = readBits(16);
                             long bNLen = readBits(16);
                             if (((bLen ^ 0xFFFF) & 0xFFFF) != bNLen) {

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/2d25368d/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/utils/BitInputStream.java b/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
index f4beaae..7f29ac0 100644
--- a/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
@@ -110,6 +110,17 @@ public class BitInputStream implements Closeable {
         return bitsCachedSize + 8l * in.available();
     }
 
+    /**
+     * Drops bits until the next bits will be read from a byte boundary.
+     * @since 1.16
+     */
+    public void alignWithByteBoundary() throws IOException {
+        int toSkip = bitsCachedSize % 8;
+        if (toSkip > 0) {
+            readBits(toSkip);
+        }
+    }
+
     private long processBitsGreater57(final int count) throws IOException {
         final long bitsOut;
         int overflowBits = 0;