GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — ProtobufVarint32FrameDecoder desynchronizes the stream when a 4-byte length prefix is split after 3 bytes · Issue #17549 · netty/netty Closed Milestone DescriptionExpected behavior
Actual behaviorSince #14050 ("Branchless varint decoding"), two incomplete-prefix cases are no longer treated as "need more data":
Before #14050 both cases were handled with Output of the reproducer below on So a single 2 MiB message is delivered to the next handler as one empty frame, one 1-byte frame and then ~2 million empty frames, without any exception. The same happens for 4 MiB (
Steps to reproduce
For the second case, feed Minimal yet complete reproducer code (or URL to code)import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder; import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender; public class VarintSplitRepro { public static void main(String[] args) { // 1) Frame a 2 MiB message with Netty's own prepender. The length prefix is 80 80 80 01. int size = 2 * 1024 * 1024; EmbeddedChannel enc = new EmbeddedChannel(new ProtobufVarint32LengthFieldPrepender()); enc.writeOutbound(Unpooled.wrappedBuffer(new byte[size])); ByteBuf wire = Unpooled.buffer(); for (ByteBuf b; (b = enc.readOutbound()) != null;) { wire.writeBytes(b); b.release(); } // 2) Deliver it in two reads, the first one ending after 3 of the 4 prefix bytes. EmbeddedChannel dec = new EmbeddedChannel(new ProtobufVarint32FrameDecoder()); dec.writeInbound(wire.retainedSlice(0, 3)); dec.writeInbound(wire.retainedSlice(3, wire.readableBytes() - 3)); int frames = 0; long bytes = 0; StringBuilder first = new StringBuilder(); for (ByteBuf f; (f = dec.readInbound()) != null;) { if (frames < 5) { first.append(f.readableBytes()).append(' '); } frames++; bytes += f.readableBytes(); f.release(); } System.out.println("expected: 1 frame of " + size + " bytes"); System.out.println("actual : " + frames + " frames, " + bytes + " payload bytes, first sizes: " + first); // 3) 5-byte prefix (length >= 2^28) where only 4 bytes have arrived yet. EmbeddedChannel dec2 = new EmbeddedChannel(new ProtobufVarint32FrameDecoder()); try { dec2.writeInbound(Unpooled.wrappedBuffer(new byte[] {(byte) 0x80, (byte) 0x80, (byte) 0x80, (byte) 0x80})); System.out.println("4 of 5 prefix bytes: waits for more data"); } catch (Exception e) { System.out.println("4 of 5 prefix bytes: " + e); } } } Netty version
JVM version (e.g.
|
| 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. |