From 8b7efa5db4f9ab69cd6fcf8768822040afc4aefd Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 21 Oct 2009 11:23:52 +0000 Subject: [PATCH] Fixed wrong byte order in gzip crc32 and isize field --- .../org/jboss/netty/util/internal/jzlib/Deflate.java | 12 ++++++++---- .../org/jboss/netty/util/internal/jzlib/Inflate.java | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jboss/netty/util/internal/jzlib/Deflate.java b/src/main/java/org/jboss/netty/util/internal/jzlib/Deflate.java index 61949fe4e3..9738647c8c 100644 --- a/src/main/java/org/jboss/netty/util/internal/jzlib/Deflate.java +++ b/src/main/java/org/jboss/netty/util/internal/jzlib/Deflate.java @@ -1656,10 +1656,14 @@ final class Deflate { break; case GZIP: // Write the gzip trailer (CRC32 & ISIZE) - putShortMSB(strm.crc32 >>> 16); - putShortMSB(strm.crc32 & 0xFFFF); - putShortMSB(gzipUncompressedBytes >>> 16); // ISIZE 1 - putShortMSB(gzipUncompressedBytes & 0xFFFF); // ISIZE 2 + put_byte((byte) (strm.crc32 & 0xFF)); + put_byte((byte) (strm.crc32 >>> 8 & 0xFF)); + put_byte((byte) (strm.crc32 >>> 16 & 0xFF)); + put_byte((byte) (strm.crc32 >>> 24 & 0xFF)); + put_byte((byte) (gzipUncompressedBytes & 0xFF)); + put_byte((byte) (gzipUncompressedBytes >>> 8 & 0xFF)); + put_byte((byte) (gzipUncompressedBytes >>> 16 & 0xFF)); + put_byte((byte) (gzipUncompressedBytes >>> 24 & 0xFF)); break; } diff --git a/src/main/java/org/jboss/netty/util/internal/jzlib/Inflate.java b/src/main/java/org/jboss/netty/util/internal/jzlib/Inflate.java index 972cd7618b..3f1f19723b 100644 --- a/src/main/java/org/jboss/netty/util/internal/jzlib/Inflate.java +++ b/src/main/java/org/jboss/netty/util/internal/jzlib/Inflate.java @@ -499,7 +499,7 @@ final class Inflate { z.avail_in --; z.total_in ++; gzipBytesToRead --; - z.istate.gzipCRC32 = z.istate.gzipCRC32 << 8 | z.next_in[z.next_in_index ++] & 0xff; + z.istate.gzipCRC32 |= (z.next_in[z.next_in_index ++] & 0xff) << (3 - gzipBytesToRead) * 8; } if (z.crc32 != z.istate.gzipCRC32) { @@ -519,7 +519,7 @@ final class Inflate { z.avail_in --; z.total_in ++; gzipBytesToRead --; - z.istate.gzipISize = z.istate.gzipISize << 8 | z.next_in[z.next_in_index ++] & 0xff; + z.istate.gzipISize |= (z.next_in[z.next_in_index ++] & 0xff) << (3 - gzipBytesToRead) * 8; } if (gzipUncompressedBytes != z.istate.gzipISize) {