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 — Codec-compression: Add zlib decompressors by yawkat · Pull Request #17155 · netty/netty

Codec-compression: Add zlib decompressors #17155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
chrisvest merged 25 commits into 4.2 from extract-zlib-decompressors
Jul 28, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Codec-compression: Add zlib decompressors #17155

Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5737cd5
Codec-compression: Add zlib decompressor base
yawkat Jul 27, 2026
731fa0b
Codec-compression: Add JZlib decompressor
yawkat Jul 27, 2026
5b23fd4
Codec-compression: Add JDK zlib decompressor
yawkat Jul 27, 2026
fb6b4d6
ZlibCodecFactory: Add decompressor builder
yawkat Jul 27, 2026
1c8a165
JZlibDecompressor: Restore parent PR implementation
yawkat Jul 27, 2026
faa1113
JdkZlibDecompressor: Restore parent PR implementation
yawkat Jul 27, 2026
238f04d
ZlibDecompressor: Restore parent PR implementation
yawkat Jul 27, 2026
29321f0
JdkZlibDecompressor: Fix GZIP FEXTRA handling
yawkat Jul 27, 2026
0685084
JdkZlibDecompressor: Report complete after GZIP footer
yawkat Jul 27, 2026
754c82e
JZlibDecompressor: Release output on failure
yawkat Jul 27, 2026
d0af116
JdkZlibDecompressor: Release inflater on close
yawkat Jul 27, 2026
517d309
ZlibDecompressor: Reject negative max allocation
yawkat Jul 27, 2026
58fcb85
JZlibDecompressor: Reject truncated input
yawkat Jul 27, 2026
1ac2e09
JdkZlibDecompressor: Reject truncated input
yawkat Jul 27, 2026
3fe084a
JdkZlibDecompressor: Release output on failure
yawkat Jul 27, 2026
31a58ca
JZlibDecompressor: Release inflater on close
yawkat Jul 27, 2026
6a980a6
JdkZlibDecompressor: Validate GZIP magic
yawkat Jul 27, 2026
b6029da
JZlibDecompressorTest: Use try-with-resources
yawkat Jul 27, 2026
80a44f1
JZlibDecompressor: Simplify inflater lifecycle
yawkat Jul 27, 2026
732cf87
JZlibDecompressorTest: Cover direct input across outputs
yawkat Jul 27, 2026
cc1cc0c
JdkZlibDecompressor: Fix dictionary error message
yawkat Jul 27, 2026
b50e971
ZlibCodecFactory: Mark decompressor APIs unstable
yawkat Jul 27, 2026
914dfb7
ZlibCodecFactory: Remove decompressor builder
yawkat Jul 28, 2026
86a0db0
Codec-compression: Remove JZlib decompressor
yawkat Jul 28, 2026
553478f
JdkZlibDecompressor: Inline zlib decompressor base
yawkat Jul 28, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

163 changes: 163 additions & 0 deletions 163 codec-compression/src/main/java/io/netty/handler/codec/compression/JZlibDecompressor.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright 2025 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.compression;

import com.jcraft.jzlib.Inflater;
import com.jcraft.jzlib.JZlib;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.internal.UnstableApi;

@UnstableApi
public class JZlibDecompressor extends ZlibDecompressor {

private final Inflater z = new Inflater();
Comment thread
yawkat marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

private boolean finished;
private boolean inputBufferInInflater;

JZlibDecompressor(Builder builder, ByteBufAllocator allocator) {
super(builder, allocator);
int resultCode;
if (dictionary == null) {
resultCode = z.init(ZlibUtil.convertWrapperType(builder.wrapper));
} else {
if (builder.wrapper != ZlibWrapper.ZLIB) {
throw new DecompressionException("Dictionary is only supported for ZLIB wrapper");
}
resultCode = z.inflateInit(JZlib.W_ZLIB);
}
if (resultCode != JZlib.Z_OK) {
ZlibUtil.fail(z, "initialization failure", resultCode);
}
}

@Override
void processInput(ByteBuf buf) throws DecompressionException {
// Configure input.
z.avail_in = buf.readableBytes();
if (buf.hasArray()) {
z.next_in = buf.array();
z.next_in_index = buf.arrayOffset() + buf.readerIndex();
inputBufferInInflater = true;
} else {
byte[] array = new byte[buf.readableBytes()];
buf.readBytes(array);
z.next_in = array;
z.next_in_index = 0;
}
Comment thread
yawkat marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}

@Override
public Status status() throws DecompressionException {
if (finished) {
return Status.COMPLETE;
} else if (z.avail_in == 0) {
return Status.NEED_INPUT;
} else {
return Status.NEED_OUTPUT;
}
}

@Override
public void endOfInput() throws DecompressionException {
Comment thread
yawkat marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}

@Override
ByteBuf processOutput(ByteBuf buf) throws DecompressionException {
int proposedCapacity = z.avail_in << 1;
int targetCapacity = maxAllocation == 0
? proposedCapacity : Math.min(maxAllocation, proposedCapacity);
ByteBuf decompressed = allocator.heapBuffer(targetCapacity);
Comment thread
yawkat marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

z.avail_out = decompressed.writableBytes();
z.next_out = decompressed.array();
z.next_out_index = decompressed.arrayOffset() + decompressed.writerIndex();

// Decompress 'in' into 'out'
int resultCode = z.inflate(JZlib.Z_SYNC_FLUSH);
decompressed.writerIndex(z.next_out_index - decompressed.arrayOffset());

if (inputBufferInInflater) {
buf.readerIndex(buf.writerIndex() - z.avail_in);
if (z.avail_in == 0) {
inputBufferInInflater = false;
}
}

switch (resultCode) {
case JZlib.Z_NEED_DICT:
if (dictionary == null) {
ZlibUtil.fail(z, "decompression failure", resultCode);
} else {
resultCode = z.inflateSetDictionary(dictionary, dictionary.length);
if (resultCode != JZlib.Z_OK) {
ZlibUtil.fail(z, "failed to set the dictionary", resultCode);
}
}
break;
case JZlib.Z_STREAM_END:
finished = true; // Do not decode anymore.
z.inflateEnd();
break;
case JZlib.Z_OK:
case JZlib.Z_BUF_ERROR:
break;
default:
ZlibUtil.fail(z, "decompression failure", resultCode);
}

return decompressed;
}

@UnstableApi
public static Builder builder() {
return new Builder();
}

@UnstableApi
public static final class Builder extends AbstractZlibDecompressorBuilder {
Builder() {
}

/**
* {@inheritDoc}
*/
@Override
public Builder wrapper(ZlibWrapper wrapper) {
return (Builder) super.wrapper(wrapper);
}

/**
* {@inheritDoc}
*/
@Override
public Builder dictionary(byte[] dictionary) {
return (Builder) super.dictionary(dictionary);
}

/**
* {@inheritDoc}
*/
@Override
public Builder maxAllocation(int maxAllocation) {
return (Builder) super.maxAllocation(maxAllocation);
}

@Override
public Decompressor build(ByteBufAllocator allocator) throws DecompressionException {
return new DefensiveDecompressor(new JZlibDecompressor(this, allocator));
}
}
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.