capnproto / capnproto-java

Cap'n Proto in pure Java
Other
391 stars 86 forks source link

Integer size limit on message read byte size #99

Closed clavin-xlnx closed 3 years ago

clavin-xlnx commented 3 years ago

Thanks for the previous fix in #97. We have run into another integer overflow issue related to representing our larger FPGA devices (see Xilinx/RapidWright#176 for reference). When we serialize a message that has a greater number of bytes than Integer.MAX_VALUE=2147483647, we get an error when we try to read it:

Exception in thread "main" java.lang.IllegalArgumentException: capacity < 0: (-1862524376 < 0)
    at java.base/java.nio.Buffer.createCapacityException(Buffer.java:256)
    at java.base/java.nio.ByteBuffer.allocate(ByteBuffer.java:347)
    at org.capnproto.Serialize.makeByteBuffer(Serialize.java:34)
    at org.capnproto.Serialize.read(Serialize.java:89)
    at com.xilinx.rapidwright.interchange.Interchange.readInterchangeFile(Interchange.java:76)
    at com.xilinx.rapidwright.interchange.DeviceResourcesVerifier.verifyDeviceResources(DeviceResourcesVerifier.java:124)
    at com.xilinx.rapidwright.interchange.DeviceResourcesExample.main(DeviceResourcesExample.java:35)

Which runs into an issue because of the use of a ByteBuffer that is allocated using an int. Since there is no option to allocate using a long, perhaps makeByteBuffer() could return an array of ByteBuffer objects and update handling accordingly?

dwrensha commented 3 years ago

Thanks for the report! This should be fixed by 4ec14e39f98aeda5d513923ad7d5be7618b2e8aa.

dwrensha commented 3 years ago

I've published 0.1.7 with the fix.