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 — ZstdEncoder not producing data when source is smaller than block size · Issue #15340 · netty/netty

ZstdEncoder not producing data when source is smaller than block size #15340

New issue
Copy link
New issue
Copy link
Closed
#15859
Closed
ZstdEncoder not producing data when source is smaller than block size#15340
#15859
Copy link
Milestone
4.1.129.Final

Description

@sephiroth-j
sephiroth-j
opened on Jun 11, 2025
Issue body actions

If the size of the input buffer is smaller than the configured block size (64 KB by default), then ZstdEncoder.write only produces an empty buffer. With the default sizes, this makes the encoder unusable for variable size content.

The actual size should be around 25 bytes.

$ echo -n 'Hello, World'|zstd -v|hexdump -C
*** Zstandard CLI (64-bit) v1.5.5, by Yann Collet ***
/*stdin*\            :208.33%   (    12 B =>     25 B, /*stdout*\)
00000000  28 b5 2f fd 04 58 61 00  00 48 65 6c 6c 6f 2c 20  |(./..Xa..Hello, |
00000010  57 6f 72 6c 64 51 c7 d3  f2                       |WorldQ...|
00000019

Of the following tests, only the first test is successful.

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.VoidChannelPromise;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.compression.ZstdEncoder;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class ZstdEncoderTest {
	static String TEST_CONTENT = "Hello, World";

	@Mock
	private ChannelHandlerContext ctx;

	@BeforeEach
	public void setup() {
		when(ctx.alloc()).thenReturn(ByteBufAllocator.DEFAULT);
	}

	@Test
	void testEncodeWithSmallBlockSize() throws Exception {
		int length = TEST_CONTENT.getBytes(StandardCharsets.UTF_8).length;
		// block size <= size of TEST_CONTENT
		testEncoder(new ZstdEncoder(length, 1024));
	}

	@Test
	void testEncodeWithLargerBlockSize() throws Exception {
		int length = TEST_CONTENT.getBytes(StandardCharsets.UTF_8).length;
		// block size > size of TEST_CONTENT
		testEncoder(new ZstdEncoder(length + 1, 1024));
	}

	@Test
	void testEncodeWithDefaults() throws Exception {
		// default block size of 64kb
		testEncoder(new ZstdEncoder());
	}

	void testEncoder(ZstdEncoder encoder) throws Exception {
		var in = Unpooled.copiedBuffer(TEST_CONTENT, StandardCharsets.UTF_8);
		var chan = new EmbeddedChannel();
		encoder.handlerAdded(ctx);
		var promise = new VoidChannelPromise(chan, true);
		encoder.write(ctx, in, promise);
		
		var outCaptor = ArgumentCaptor.forClass(ByteBuf.class);
		verify(ctx).write(outCaptor.capture(), eq(promise));
		
		var out = outCaptor.getValue();
		assertThat(out.readableBytes()).isPositive();
		out.release();
	}
}

Activity

  1. sephiroth-j commented on Jun 12, 2025

    @sephiroth-j
    sephiroth-j
    on Jun 12, 2025
    Author
    More actions

    https://datatracker.ietf.org/doc/html/rfc8478#section-3.1.1.2.3

    A Compressed_Block has the extra restriction that Block_Size is always strictly less than the decompressed size. If this condition cannot be respected, the block must be sent uncompressed instead (i.e., treated as a Raw_Block).

    Could the last part be missing?

  2. normanmaurer commented on Sep 16, 2025

    @normanmaurer
    normanmaurer
    on Sep 16, 2025
    Member
    More actions

    Need to have a look

  3. normanmaurer
    added this to the 4.1.128.Final milestone on Sep 16, 2025
  4. normanmaurer
    modified the milestones: 4.1.128.Final, 4.1.129.Final on Oct 13, 2025
  5. skyguard1 commented on Nov 14, 2025

    @skyguard1
    skyguard1
    on Nov 14, 2025
    Contributor
    More actions

    I think we can fix this

  6. normanmaurer commented on Nov 14, 2025

    @normanmaurer
    normanmaurer
    on Nov 14, 2025
    Member
    More actions

    @skyguard1 can you do a PR ?

  7. normanmaurer
    added a commit that references this issue on Nov 19, 2025

    Fix ZstdEncoder not producing data when source is smaller than block …

    5679ca2
  8. normanmaurer
    closed this as completedin #15859on Nov 19, 2025
  9. normanmaurer
    added 4 commits that reference this issue on Nov 19, 2025

    Fix ZstdEncoder not producing data when source is smaller than block …

    96f1c81

    Fix ZstdEncoder not producing data when source is smaller than block …

    55bc723

    Fix ZstdEncoder not producing data when source is smaller than block … (

    84dce5b

    Fix ZstdEncoder not producing data when source is smaller than block … (

    416540a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.1.129.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.