GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Check the second gzip magic byte in JdkZlibDecoder (#17972) · netty/netty@f69f14a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-compression/src
    • main/java/io/netty/handler/codec/compression
      • JdkZlibDecoder.java
    • test/java/io/netty/handler/codec/compression
      • JdkZlibTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-compression/src/main/java/io/netty/handler/codec/compression/JdkZlibDecoder.java‎

Copy file name to clipboardExpand all lines: codec-compression/src/main/java/io/netty/handler/codec/compression/JdkZlibDecoder.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,10 @@ private boolean readGZIPHeader(ByteBuf in) {
381381
return false;
382382
}
383383
// read magic numbers
384-
int magic0 = in.readByte();
385-
int magic1 = in.readByte();
384+
int magic0 = in.readUnsignedByte();
385+
int magic1 = in.readUnsignedByte();
386386

387-
if (magic0 != 31) {
387+
if (magic0 != 31 || magic1 != 139) {
388388
throw new DecompressionException("Input is not in the GZIP format");
389389
}
390390
crc.update(magic0);
Collapse file

‎codec-compression/src/test/java/io/netty/handler/codec/compression/JdkZlibTest.java‎

Copy file name to clipboardExpand all lines: codec-compression/src/test/java/io/netty/handler/codec/compression/JdkZlibTest.java
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,26 @@ public void testGzipFooterCrcMismatchThrows() throws Exception {
462462
ch.finishAndReleaseAll();
463463
}
464464

465+
@Test
466+
public void testGzipInvalidSecondMagicByteThrows() throws Exception {
467+
byte[] data = "hello gzip".getBytes(CharsetUtil.UTF_8);
468+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
469+
GZIPOutputStream gzipOut = new GZIPOutputStream(baos);
470+
gzipOut.write(data);
471+
gzipOut.close();
472+
473+
byte[] compressed = baos.toByteArray();
474+
// Replace ID2 (0x8b) of the header.
475+
compressed[1] = 0;
476+
477+
EmbeddedChannel ch = new EmbeddedChannel(new JdkZlibDecoder(ZlibWrapper.GZIP, Integer.MAX_VALUE));
478+
assertThrows(DecompressionException.class, () -> {
479+
ch.writeInbound(Unpooled.wrappedBuffer(compressed));
480+
});
481+
// the remaining input is decoded again when the channel is closed
482+
assertThrows(DecompressionException.class, ch::finishAndReleaseAll);
483+
}
484+
465485
@Test
466486
public void testGzipFooterISizeMismatchThrows() throws Exception {
467487
byte[] data = "wrong size".getBytes(CharsetUtil.UTF_8);

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.