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 — Make public API specify explicit maxAllocation to prevent OOM by DeviLab · Pull Request #15005 · netty/netty Conversation
Contributor
Motivation: The current Modification:
Result: This change does not modify the public API behavior, but it encourages users to adopt the updated methods, which include the explicit Fixes #6663.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
The stack trace provided shows io.netty.handler.codec.compression.ZlibDecoder.prepareDecompressBuffer(ZlibDecoder.java:74) Which looks like is hitting a reallocation due to wrong estimated buffer capacity - is it expected? And not only: the allocated buffer is unpooled and big, which makes it even worse. And indeed I see the comment at netty/codec-compression/src/main/java/io/netty/handler/codec/compression/ZlibDecoder.java Line 71 in 620794f
I am not a zlib expert, so it is from the allocator pov |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The the problem is that I as a third-party developer can't stop their user from sending 10 GB repeating string, which is compressed into a couple of kilobytes. I got the stacktrace above exactly with such manipulations. There only way to prevent it is to limit maximum decompressed size. It has been done before in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I checked why the pipeline failed. It looks like unrelated to my change: JVM is suddenly crashed on |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| this.compressionLevel = compressionLevel; | ||
| this.useWebkitExtensionName = useWebkitExtensionName; | ||
| this.extensionFilterProvider = checkNotNull(extensionFilterProvider, "extensionFilterProvider"); | ||
| this.maxAllocation = maxAllocation; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should we check that this is >= 0 ?. There are utilities in ObjectUtils for this. This is true for all constructors
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added to all public constructors
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this work!
I had some comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return newZlibDecoder(0); | ||
| } | ||
|
|
||
| public static ZlibDecoder newZlibDecoder(int maxAllocation) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please add javadocs, here and elsewhere, that explain the parameters.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
+1, please also add @deprecated javadoc tag where necessary with explanation what users should use instead of the deprecated methods
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added to every newZlibDecoder method
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| return newZlibDecoder(0); | ||
| } | ||
|
|
||
| public static ZlibDecoder newZlibDecoder(int maxAllocation) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
+1, please also add @deprecated javadoc tag where necessary with explanation what users should use instead of the deprecated methods
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@DeviLab thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Motivation: The current `ZLibCodecFactory` provides `newZlibDecoder` methods without an option to specify a maximum memory limit for decompression. These methods are utilized in various parts of the project, such as the per-message WebSocket extension. As a result, a client could send a small, maliciously crafted compressed message that, upon decompression, would consume all available memory. This can lead to an `OutOfMemoryError` scenario, which can easily be reproduced as follows: ``` Exception in thread "io-compute-15" java.lang.OutOfMemoryError: Java heap space at io.netty.util.internal.PlatformDependent.allocateUninitializedArray(PlatformDependent.java:326) at io.netty.buffer.PoolArena$HeapArena.newByteArray(PoolArena.java:628) at io.netty.buffer.PoolArena$HeapArena.newUnpooledChunk(PoolArena.java:652) at io.netty.buffer.PoolArena.allocateHuge(PoolArena.java:224) at io.netty.buffer.PoolArena.allocate(PoolArena.java:142) at io.netty.buffer.PoolArena.reallocate(PoolArena.java:317) at io.netty.buffer.PooledByteBuf.capacity(PooledByteBuf.java:123) at io.netty.buffer.AbstractByteBuf.ensureWritable(AbstractByteBuf.java:333) at io.netty.handler.codec.compression.ZlibDecoder.prepareDecompressBuffer(ZlibDecoder.java:74) at io.netty.handler.codec.compression.JdkZlibDecoder.decode(JdkZlibDecoder.java:265) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868) at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:348) at io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.decompressContent(DeflateDecoder.java:119) at io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.decode(DeflateDecoder.java:80) at io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateDecoder.decode(PerMessageDeflateDecoder.java:87) at io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateDecoder.decode(PerMessageDeflateDecoder.java:31) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) java.lang.OutOfMemoryError: Java heap space at io.netty.util.internal.PlatformDependent.allocateUninitializedArray(PlatformDependent.java:326) at io.netty.buffer.PoolArena$HeapArena.newByteArray(PoolArena.java:628) at io.netty.buffer.PoolArena$HeapArena.newUnpooledChunk(PoolArena.java:652) ``` Modification: - Introduced new `newZlibDecoder` methods within `ZlibCodecFactory` that include an explicit `maxAllocation` parameter to specify the maximum allowed memory during decompression. - The older methods have been deprecated in favor of the new ones. - Public APIs that invoke `newZlibDecoder` now require the `maxAllocation` parameter as well. Result: This change does not modify the public API behavior, but it encourages users to adopt the updated methods, which include the explicit `maxAllocation` argument, providing more control over memory usage during decompression. Fixes #6663.
#15122) Motivation: The current `ZLibCodecFactory` provides `newZlibDecoder` methods without an option to specify a maximum memory limit for decompression. These methods are utilized in various parts of the project, such as the per-message WebSocket extension. As a result, a client could send a small, maliciously crafted compressed message that, upon decompression, would consume all available memory. This can lead to an `OutOfMemoryError` scenario, which can easily be reproduced as follows: ``` Exception in thread "io-compute-15" java.lang.OutOfMemoryError: Java heap space at io.netty.util.internal.PlatformDependent.allocateUninitializedArray(PlatformDependent.java:326) at io.netty.buffer.PoolArena$HeapArena.newByteArray(PoolArena.java:628) at io.netty.buffer.PoolArena$HeapArena.newUnpooledChunk(PoolArena.java:652) at io.netty.buffer.PoolArena.allocateHuge(PoolArena.java:224) at io.netty.buffer.PoolArena.allocate(PoolArena.java:142) at io.netty.buffer.PoolArena.reallocate(PoolArena.java:317) at io.netty.buffer.PooledByteBuf.capacity(PooledByteBuf.java:123) at io.netty.buffer.AbstractByteBuf.ensureWritable(AbstractByteBuf.java:333) at io.netty.handler.codec.compression.ZlibDecoder.prepareDecompressBuffer(ZlibDecoder.java:74) at io.netty.handler.codec.compression.JdkZlibDecoder.decode(JdkZlibDecoder.java:265) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868) at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:348) at io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.decompressContent(DeflateDecoder.java:119) at io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.decode(DeflateDecoder.java:80) at io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateDecoder.decode(PerMessageDeflateDecoder.java:87) at io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateDecoder.decode(PerMessageDeflateDecoder.java:31) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) java.lang.OutOfMemoryError: Java heap space at io.netty.util.internal.PlatformDependent.allocateUninitializedArray(PlatformDependent.java:326) at io.netty.buffer.PoolArena$HeapArena.newByteArray(PoolArena.java:628) at io.netty.buffer.PoolArena$HeapArena.newUnpooledChunk(PoolArena.java:652) ``` Modification: - Introduced new `newZlibDecoder` methods within `ZlibCodecFactory` that include an explicit `maxAllocation` parameter to specify the maximum allowed memory during decompression. - The older methods have been deprecated in favor of the new ones. - Public APIs that invoke `newZlibDecoder` now require the `maxAllocation` parameter as well. Result: This change does not modify the public API behavior, but it encourages users to adopt the updated methods, which include the explicit `maxAllocation` argument, providing more control over memory usage during decompression. Fixes #6663. Co-authored-by: DeviLab <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
WebSocket compression can increase data size, even when this exceeds max frame size
There was an error while loading. Please reload this page.