xXDylanDog13Xx / kryonet

Automatically exported from code.google.com/p/kryonet
1 stars 1 forks source link

Prone to BufferOverflow #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
http://code.google.com/p/kryonet/source/browse/trunk/kryonet/src/com/esotericsof
tware/kryonet/TcpConnection.java#197

From there, and especially on line 199:

writeBuffer.put(tempWriteBuffer);

No check on Buffer overflow is done. This problem probably does not occur much 
since it uses 16000 byte buffers by default.

Original issue reported on code.google.com by Nephir...@gmail.com on 9 Aug 2010 at 10:30

GoogleCodeExporter commented 9 years ago
Thanks for taking a look. That piece of code is very core, so it is good to 
have eyes on it.

Here's a quick overview of that piece of code: objects are serialized to the 
"temp write buffer" which is then written to socket. Almost always this will 
succeed, but if not, the temp buffer is copied to the larger "write buffer" to 
be written later. This way the ideal scenario doesn't have any extra memory 
copies. Also this allows us to write the length of serialized object before the 
object without any extra memory copies.

I've added exception handling for the write buffer overflow. I rethrow a 
SerializationException, which will cause the connection to be closed. This is 
much better than a server crash, which was the previous behavior.

Thanks!

Original comment by nathan.s...@gmail.com on 9 Aug 2010 at 11:06