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 — BrotliDecompressor: reject truncated input · netty/netty@074a42a

File tree

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

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

Copy file name to clipboardExpand all lines: codec-compression/src/main/java/io/netty/handler/codec/compression/BrotliDecompressor.java
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ private void addSomeInput(ByteBuf buf) {
111111

112112
@Override
113113
public void endOfInput() throws DecompressionException {
114+
if (decoder.getStatus() == DecoderJNI.Status.NEEDS_MORE_INPUT) {
115+
assert unusedInput == null : "Expected to be in NEED_INPUT state";
116+
decoder.push(0);
117+
if (decoder.getStatus() == DecoderJNI.Status.NEEDS_MORE_INPUT) {
118+
throw new DecompressionException("Truncated brotli stream");
119+
}
120+
}
114121
}
115122

116123
@Override
Collapse file

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

Copy file name to clipboardExpand all lines: codec-compression/src/test/java/io/netty/handler/codec/compression/BrotliDecompressorTest.java
+28-1Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
import io.netty.buffer.ByteBuf;
1919
import io.netty.buffer.ByteBufAllocator;
20-
import org.junit.jupiter.api.Test;
2120
import io.netty.channel.ChannelHandler;
21+
import org.junit.jupiter.api.Test;
2222

2323
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertThrows;
2425

2526
public class BrotliDecompressorTest extends AbstractDecompressorTest {
2627
@Override
@@ -52,4 +53,30 @@ public void reportsOutputBeforeMoreInput() throws Exception {
5253
}
5354
}
5455
}
56+
57+
@Test
58+
public void endOfInputRejectsTruncatedStream() throws Exception {
59+
ByteBuf[] data = smallData();
60+
ByteBuf truncated = data[0].readRetainedSlice(data[0].readableBytes() - 1);
61+
62+
try (Decompressor decompressor = createDecompressor().build(ByteBufAllocator.DEFAULT)) {
63+
assertEquals(Decompressor.Status.NEED_INPUT, decompressor.status());
64+
decompressor.addInput(truncated);
65+
truncated = null;
66+
67+
while (decompressor.status() == Decompressor.Status.NEED_OUTPUT) {
68+
decompressor.takeOutput().release();
69+
}
70+
71+
assertEquals(Decompressor.Status.NEED_INPUT, decompressor.status());
72+
assertThrows(DecompressionException.class, decompressor::endOfInput);
73+
} finally {
74+
if (truncated != null) {
75+
truncated.release();
76+
}
77+
for (ByteBuf buffer : data) {
78+
buffer.release();
79+
}
80+
}
81+
}
5582
}

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.