private boolean readGZIPFooter(ByteBuf buf) { if (buf.readableBytes() < 8) { return false; } verifyCrc(buf); // read ISIZE and verify int dataLength = 0; for (int i = 0; i < 4; ++i) { dataLength |= buf.readUnsignedByte() << i * 8; } int readLength = inflater.getTotalOut(); if (dataLength != readLength) { throw new DecompressionException( "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength); } return true; }
private boolean readGZIPFooter(ByteBuf buf) { if (buf.readableBytes() < 8) { return false; } verifyCrc(buf); // read ISIZE and verify int dataLength = 0; for (int i = 0; i < 4; ++i) { dataLength |= buf.readUnsignedByte() << i * 8; } int readLength = inflater.getTotalOut(); if (dataLength != readLength) { throw new DecompressionException( "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength); } return true; }
private void verifyCrc() throws IOException { // Get non-compressed bytes read by fill int size = inf.getRemaining(); final int trailerSize = 8; // crc (4 bytes) + total out (4 bytes) byte[] b = new byte[trailerSize]; int copySize = (size > trailerSize) ? trailerSize : size; System.arraycopy(buf, len - size, b, 0, copySize); readFully(b, copySize, trailerSize - copySize); if (Memory.peekInt(b, 0, ByteOrder.LITTLE_ENDIAN) != (int) crc.getValue()) { throw new IOException("CRC mismatch"); } if (Memory.peekInt(b, 4, ByteOrder.LITTLE_ENDIAN) != inf.getTotalOut()) { throw new IOException("Size mismatch"); } }
private boolean readGZIPFooter(ByteBuf buf) { if (buf.readableBytes() < 8) { return false; } verifyCrc(buf); // read ISIZE and verify int dataLength = 0; for (int i = 0; i < 4; ++i) { dataLength |= buf.readUnsignedByte() << i * 8; } int readLength = inflater.getTotalOut(); if (dataLength != readLength) { throw new DecompressionException( "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength); } return true; }
if (currentEntry.compressionMethod == ZipEntry.DEFLATED) { inB = inf.getTotalIn(); out = inf.getTotalOut(); } else { inB = inRead;
private void verifyFooter() throws IOException { byte footer[] = _lookaheadStream.getFooter(); long actualSize = inf.getTotalOut(); long expectedSize = DataHelper.fromLongLE(footer, 4, 4); if (expectedSize != actualSize) throw new IOException("gunzip expected " + expectedSize + " bytes, got " + actualSize); long actualCRC = _crc32.getValue(); long expectedCRC = DataHelper.fromLongLE(footer, 0, 4); if (expectedCRC != actualCRC) throw new IOException("gunzip CRC fail expected 0x" + Long.toHexString(expectedCRC) + " bytes, got 0x" + Long.toHexString(actualCRC)); }
/** * @throws IOException on CRC or length check fail */ private void verifyFooter() throws IOException { int idx = (int) (_bytesReceivedAtCompletion % FOOTER_SIZE); byte[] footer; if (idx == 0) { footer = _footer; } else { footer = new byte[FOOTER_SIZE]; for (int i = 0; i < FOOTER_SIZE; i++) { footer[i] = _footer[(int) ((_bytesReceivedAtCompletion + i) % FOOTER_SIZE)]; } } long actualSize = inf.getTotalOut(); long expectedSize = DataHelper.fromLongLE(footer, 4, 4); if (expectedSize != actualSize) throw new IOException("gunzip expected " + expectedSize + " bytes, got " + actualSize); long actualCRC = _crc32.getValue(); long expectedCRC = DataHelper.fromLongLE(footer, 0, 4); if (expectedCRC != actualCRC) throw new IOException("gunzip CRC fail expected 0x" + Long.toHexString(expectedCRC) + " bytes, got 0x" + Long.toHexString(actualCRC)); }
protected int internalTotalOut() { return infl.getInflater().getTotalOut(); }
private void verifyCrc() throws IOException { // Get non-compressed bytes read by fill int size = inf.getRemaining(); final int trailerSize = 8; // crc (4 bytes) + total out (4 bytes) byte[] b = new byte[trailerSize]; int copySize = (size > trailerSize) ? trailerSize : size; System.arraycopy(buf, len - size, b, 0, copySize); readFully(b, copySize, trailerSize - copySize); if (Memory.peekInt(b, 0, ByteOrder.LITTLE_ENDIAN) != (int) crc.getValue()) { throw new IOException("CRC mismatch"); } if (Memory.peekInt(b, 4, ByteOrder.LITTLE_ENDIAN) != inf.getTotalOut()) { throw new IOException("Size mismatch"); } }
private void verifyCrc() throws IOException { // Get non-compressed bytes read by fill int size = inf.getRemaining(); final int trailerSize = 8; // crc (4 bytes) + total out (4 bytes) byte[] b = new byte[trailerSize]; int copySize = (size > trailerSize) ? trailerSize : size; System.arraycopy(buf, len - size, b, 0, copySize); readFully(b, copySize, trailerSize - copySize); if (Memory.peekInt(b, 0, ByteOrder.LITTLE_ENDIAN) != (int) crc.getValue()) { throw new IOException("CRC mismatch"); } if (Memory.peekInt(b, 4, ByteOrder.LITTLE_ENDIAN) != inf.getTotalOut()) { throw new IOException("Size mismatch"); } }
private void verifyCrc() throws IOException { // Get non-compressed bytes read by fill int size = inf.getRemaining(); final int trailerSize = 8; // crc (4 bytes) + total out (4 bytes) byte[] b = new byte[trailerSize]; int copySize = (size > trailerSize) ? trailerSize : size; System.arraycopy(buf, len - size, b, 0, copySize); readFully(b, copySize, trailerSize - copySize); if (Memory.peekInt(b, 0, ByteOrder.LITTLE_ENDIAN) != (int) crc.getValue()) { throw new IOException("CRC mismatch"); } if (Memory.peekInt(b, 4, ByteOrder.LITTLE_ENDIAN) != inf.getTotalOut()) { throw new IOException("Size mismatch"); } }
private void verifyCrc() throws IOException { // Get non-compressed bytes read by fill int size = inf.getRemaining(); final int trailerSize = 8; // crc (4 bytes) + total out (4 bytes) byte[] b = new byte[trailerSize]; int copySize = (size > trailerSize) ? trailerSize : size; System.arraycopy(buf, len - size, b, 0, copySize); readFully(b, copySize, trailerSize - copySize); if (Memory.peekInt(b, 0, ByteOrder.LITTLE_ENDIAN) != (int) crc.getValue()) { throw new IOException("CRC mismatch"); } if (Memory.peekInt(b, 4, ByteOrder.LITTLE_ENDIAN) != inf.getTotalOut()) { throw new IOException("Size mismatch"); } }
private static String toDetail(Inflater inflater) { return String.format("Inflater[finished=%b,read=%d,written=%d,remaining=%d,in=%d,out=%d]", inflater.finished(), inflater.getBytesRead(), inflater.getBytesWritten(), inflater.getRemaining(), inflater.getTotalIn(), inflater.getTotalOut()); }
private static String toDetail(Inflater inflater) { return String.format("Inflater[finished=%b,read=%d,written=%d,remaining=%d,in=%d,out=%d]", inflater.finished(), inflater.getBytesRead(), inflater.getBytesWritten(), inflater.getRemaining(), inflater.getTotalIn(), inflater.getTotalOut()); }
private boolean readGZIPFooter(ByteBuf buf) { if (buf.readableBytes() < 8) { return false; } verifyCrc(buf); // read ISIZE and verify int dataLength = 0; for (int i = 0; i < 4; ++i) { dataLength |= buf.readUnsignedByte() << i * 8; } int readLength = inflater.getTotalOut(); if (dataLength != readLength) { throw new DecompressionException( "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength); } return true; }
private static String toDetail(Inflater inflater) { return String.format("Inflater[finished=%b,read=%d,written=%d,remaining=%d,in=%d,out=%d]",inflater.finished(),inflater.getBytesRead(), inflater.getBytesWritten(),inflater.getRemaining(),inflater.getTotalIn(),inflater.getTotalOut()); }
private boolean readGZIPFooter(ByteBuf buf) { if (buf.readableBytes() < 8) { return false; } verifyCrc(buf); // read ISIZE and verify int dataLength = 0; for (int i = 0; i < 4; ++i) { dataLength |= buf.readUnsignedByte() << i * 8; } int readLength = inflater.getTotalOut(); if (dataLength != readLength) { throw new DecompressionException( "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength); } return true; }
private void consumeTrailer() throws IOException { // Read the eight-byte trailer. Confirm the body's CRC and size. // +---+---+---+---+---+---+---+---+ // | CRC32 | ISIZE | // +---+---+---+---+---+---+---+---+ checkEqual("CRC", source.readIntLe(), (int) crc.getValue()); checkEqual("ISIZE", source.readIntLe(), inflater.getTotalOut()); }
private void consumeTrailer() throws IOException { // Read the eight-byte trailer. Confirm the body's CRC and size. // +---+---+---+---+---+---+---+---+ // | CRC32 | ISIZE | // +---+---+---+---+---+---+---+---+ checkEqual("CRC", source.readIntLe(), (int) crc.getValue()); checkEqual("ISIZE", source.readIntLe(), inflater.getTotalOut()); }
private boolean readGZIPFooter(ByteBuf buf) { if (buf.readableBytes() < 8) { return false; } verifyCrc(buf); // read ISIZE and verify int dataLength = 0; for (int i = 0; i < 4; ++i) { dataLength |= buf.readUnsignedByte() << i * 8; } int readLength = inflater.getTotalOut(); if (dataLength != readLength) { throw new DecompressionException( "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength); } return true; }