kryo icon indicating copy to clipboard operation
kryo copied to clipboard

The Input class changes its buffer when deserialize a string

Open NPE0 opened this issue 1 year ago • 2 comments

Describe the bug kryo 4... When I use a single byte[] array to deserialize from multiple streams, sometimes there is a crash with the error

com.esotericsoftware.kryo.kryo5.io.KryoBufferUnderflowException: Buffer underflow

This is a real scenario when using a cache that contains data shared between threads. As I see, it is a known problem in readAscii method. Because it was fixed in 5.. version of the library. But I think it will be good to fix it in 4... version family too.

At the moment, I fixed this by simply copying the input array to a new one. In terms of cost, this is similar to using an intermediate char[] buffer in "readAscii"

To Reproduce I wrote a test that reproduces the situation. See "*Additional context".

Environment:

  • JDK Version: [1.8]
  • Kryo Version: [4.0.2]

Additional context KryoBugLab.zip

NPE0 avatar Mar 05 '24 10:03 NPE0

Is the fix backwards compatible? If it is, you could provide a PR that backports it to Kryo 4.

I don't actively maintain Kryo 4 anymore, but if users provide fixes, I can do a release.

theigl avatar Mar 05 '24 10:03 theigl

Getting same issue with the latest Kryo version

Caused by: com.esotericsoftware.kryo.io.KryoBufferUnderflowException: Buffer underflow.
	at com.esotericsoftware.kryo.io.Input.require(Input.java:221)
	at com.esotericsoftware.kryo.io.Input.readVarInt(Input.java:447)
	at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:145)
	at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:758)
	at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:869)
	at org.redisson.codec.Kryo5Codec$4.decode(Kryo5Codec.java:153)
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:454)
	at org.redisson.client.handler.CommandDecoder.decodeCommandBatch(CommandDecoder.java:308)
	at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:234)
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:150)
	at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:126)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection

mrniko avatar Apr 05 '24 10:04 mrniko

Closing for now. Please re-open if you can provide additional info.

theigl avatar Jun 17 '24 16:06 theigl