netty / netty/netty

max_window_bits is inclusive of 8 for WebSocket permessage-deflate compression

Open
#8,702 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
35.1k
Forks
16.3k
Avg merge
1d 5h
Merged PRs (30d)
143

Description

Expected behavior

It should be possible to have the window size for permessage-deflate compression as 8 according to the spec: https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-13#section-8.1.2

Actual behavior

Though it is allowed the encoding of a WebSocket frame when the window size is 8 fails:

io.netty.handler.codec.EncoderException: java.lang.IllegalArgumentException: windowBits: 8 (expected: 9-15)
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:107)
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
	at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801)
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814)
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794)
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:837)
	at websocket.WebSocketClientHandler.channelRead0(WebSocketClientHandler.java:108)
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297)
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: windowBits: 8 (expected: 9-15)
	at io.netty.handler.codec.compression.JZlibEncoder.<init>(JZlibEncoder.java:126)
	at io.netty.handler.codec.compression.ZlibCodecFactory.newZlibEncoder(ZlibCodecFactory.java:81)
	at io.netty.handler.codec.http.websocketx.extensions.compression.DeflateEncoder.encode(DeflateEncoder.java:74)
	at io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateEncoder.encode(PerMessageDeflateEncoder.java:66)
	at io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateEncoder.encode(PerMessageDeflateEncoder.java:30)
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89)
	... 38 more
Steps to reproduce

Create a client implementation as in the following project:
https://github.com/riyafa/netty-websocket-compression.git

Note that I am using a custom WebSocketClientCompressionHandler

Use the autobahn testsuite and run the server. Use the following content in the fuzzingserver.json file:

{
   "url": "ws://127.0.0.1:9001",
   "outdir": "./reports/clients",
   "cases": ["13.5.1"],
   "exclude-cases": [],
   "exclude-agent-cases": {}
}

Simply run the main method of the WebSocketClient after starting the autobahn server.
If using any other server the response from server should be something similar to the following:

HTTP/1.1 101 Switching Protocols
Server: AutobahnTestSuite/0.8.0-0.10.9
X-Powered-By: AutobahnPython/0.10.9
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Accept: R7uAXLScZyB71yTc1JmRuFVSIo8=
Sec-WebSocket-Extensions: permessage-deflate; client_no_context_takeover; client_max_window_bits=8
content-length: 0

with client_max_window_bits=8

Minimal yet complete reproducer code (or URL to code)

https://github.com/riyafa/netty-websocket-compression.git

Netty version

4.1.32.Final

JVM version (e.g. java -version)

1.8.0_191

OS version (e.g. uname -a)

Ubuntu 18.10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with PerMessageDeflateEncoder, DeflateEncoder, and JZlibEncoder, which appear in the reported stack trace, and reproduce the failure using Autobahn test case 13.5.1 or the linked WebSocketClient project. Trace how client_max_window_bits=8 reaches the encoder. Done means encoding succeeds for a negotiated window size of 8 without the reported exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.