Home / Function/ testZipBomb() — netty Function Reference

testZipBomb() — netty Function Reference

Architecture documentation for the testZipBomb() function in HttpContentDecompressorTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  0afab2e6_76f5_24bb_602b_64872d230720["testZipBomb()"]
  ad239479_d432_6bb8_104c_16b5ed7eb774["HttpContentDecompressorTest"]
  0afab2e6_76f5_24bb_602b_64872d230720 -->|defined in| ad239479_d432_6bb8_104c_16b5ed7eb774
  2b835559_a88a_cf39_e7f9_216c45d3a41e["ZipBombIncomingHandler()"]
  0afab2e6_76f5_24bb_602b_64872d230720 -->|calls| 2b835559_a88a_cf39_e7f9_216c45d3a41e
  style 0afab2e6_76f5_24bb_602b_64872d230720 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java lines 98–150

    @ParameterizedTest
    @MethodSource("encodings")
    @DisabledForSlowLeakDetection
    public void testZipBomb(String encoding) {
        int chunkSize = 1024 * 1024;
        int numberOfChunks = 256;
        int memoryLimit = chunkSize * 128;

        EmbeddedChannel compressionChannel = new EmbeddedChannel(new HttpContentCompressor());
        DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
        req.headers().set(HttpHeaderNames.ACCEPT_ENCODING, encoding);
        compressionChannel.writeInbound(req);

        DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
        compressionChannel.writeOutbound(response);

        for (int i = 0; i < numberOfChunks; i++) {
            ByteBuf buffer = compressionChannel.alloc().buffer(chunkSize);
            buffer.writeZero(chunkSize);
            compressionChannel.writeOutbound(new DefaultHttpContent(buffer));
        }
        compressionChannel.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
        compressionChannel.finish();
        compressionChannel.releaseInbound();

        ByteBuf compressed = compressionChannel.alloc().buffer();
        HttpMessage message = null;
        while (true) {
            HttpObject obj = compressionChannel.readOutbound();
            if (obj == null) {
                break;
            }
            if (obj instanceof HttpMessage) {
                message = (HttpMessage) obj;
            }
            if (obj instanceof HttpContent) {
                HttpContent content = (HttpContent) obj;
                compressed.writeBytes(content.content());
                content.release();
            }
        }

        PooledByteBufAllocator allocator = new PooledByteBufAllocator(false);

        ZipBombIncomingHandler incomingHandler = new ZipBombIncomingHandler(memoryLimit);
        EmbeddedChannel decompressChannel = new EmbeddedChannel(new HttpContentDecompressor(0), incomingHandler);
        decompressChannel.config().setAllocator(allocator);
        decompressChannel.writeInbound(message);
        decompressChannel.writeInbound(new DefaultLastHttpContent(compressed));

        assertEquals((long) chunkSize * numberOfChunks, incomingHandler.total);
    }

Domain

Subdomains

Frequently Asked Questions

What does testZipBomb() do?
testZipBomb() is a function in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java.
Where is testZipBomb() defined?
testZipBomb() is defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpContentDecompressorTest.java at line 98.
What does testZipBomb() call?
testZipBomb() calls 1 function(s): ZipBombIncomingHandler.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free