jankotek / mapdb

MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap-memory. It is a fast and easy to use embedded Java database engine.
https://mapdb.org
Apache License 2.0
4.87k stars 872 forks source link

DataOutput2 ArrayOutOfBoundsException #983

Open mwohlan opened 3 years ago

mwohlan commented 3 years ago

I was running into an issue today where writeInt() from the DataOutput2 class threw an ArrayOutOfBoundsException. It was trying to write to position 1073741824 in the Buffer Array. As far as I can tell, ensureAvail() calls grow() which tries to double the Arraysize with DataIO.nextPowTwo(n) which then results in a negative value because 1073741824*2 equals maxInt+1. newsize = Math.max(DataIO.nextPowTwo(n),buf.length) then keeps the old size, leading to an OutOfBoundsException on the next write to the byte buffer.