CompositeByteBuf.addComponent doesn't guard agaist overflow
See original GitHub issueExpected behavior
CompositeByteBuf.addComponent
should throw an exception when adding a component overflows the maximum size of the buffer (Integer.MAX_VALUE
).
Actual behavior
Both writableBytes
and/or readableBytes
(depending on setting for increaseWriterIndex
) as well as capacity
overflow into negative numbers.
Steps to reproduce
Run the reproducer in scala. Use a higher setting, e.g. -Xmx8G
to experience the issue before running out of heap. Output will be something like:
400000000 400000000
800000000 800000000
1200000000 1200000000
1600000000 1600000000
2000000000 2000000000
-1894967296 -1894967296
-1494967296 -1494967296
-1094967296 -1094967296
-694967296 -694967296
-294967296 -294967296
105032704 105032704
...
Minimal yet complete reproducer code (or URL to code)
import io.netty.buffer.{ ByteBufAllocator, Unpooled }
object BufTest {
def main(args: Array[String]): Unit = {
val alloc = ByteBufAllocator.DEFAULT
val buf = alloc.compositeBuffer()
// We'll keep adding 400MB components
while (true) {
val arr = new Array[Byte](400 * 1000 * 1000)
buf.addComponent(Unpooled.wrappedBuffer(arr))
println(s"${buf.writableBytes()} ${buf.capacity()}")
}
}
}
Netty version
4.1.44 final
JVM version (e.g. java -version
)
openjdk version "11.0.5" 2019-10-15 LTS
OpenJDK Runtime Environment Zulu11.35+15-CA (build 11.0.5+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.35+15-CA (build 11.0.5+10-LTS, mixed mode)
OS version (e.g. uname -a
)
Darwin Attilas-MacBook-Pro-4.local 18.7.0 Darwin Kernel Version 18.7.0: Mon Feb 10 21:08:45 PST 2020; root:xnu-4903.278.28~1/RELEASE_X86_64 x86_64
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
CompositeByteBuf has readableBytes return 0 - Stack Overflow
you can use addComponent(boolean increaseWriterIndex, ByteBuf buffer) with netty-4.1.x, when method param increaseWriterIndex is set true, ...
Read more >CompositeByteBuf (Netty API Reference (4.1.85.Final))
Be aware that this method does not increase the writerIndex of the CompositeByteBuf . If you need to have it increased use addComponent(boolean,...
Read more >io.netty.handler.ssl.SslHandler.java Source code - Java2s.com
CompositeByteBuf ; import io.netty.buffer. ... which works with multiple {@link ByteBuffer}s * and which does not need to do extra memory copies.
Read more >Log - d91cae2fc7b5d807d90062ab228237750c9b768f - aerofs ...
addComponent * handles buffer in consistent way and not causes leaks by Norman Maurer · 8 ... 94c6c83 [#3377] Faster overflow guard when...
Read more >Netty框架源码解析_不想当裁缝的厨子不是好程序员的博客
TRUE) == null) { // Guard against re-entrance. try {// 这个init方法一般 ... overflow OK here } /** 引用计数+1 */ @Override public ByteBuf ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In one word: heavily 😄. All of network communication is async I/O based on Netty socket channel handler pipelines. We use the ByteBuf API pervasively too even outside of immediate domain of networking (disk I/O, internal transformations). It’s a nice (consistent, comprehensive, easy to understand) API to manipulate byte-based data, and if we’re smart about it then we also minimize copying when it’s time to send the bytes over the network.
@szegedi no problem … happy to help. Would love to hear more about how faunadb uses netty 😃