BufferOverflowException for certain cachePercent and file sizes #72
Given version 1.3.1, and a file of size between 100 and 799 bytes, with a cachePercent of 1.
For small files that use a small cache, the cache buffer that is generated can be too small. This is due to how the cache is generated. In the constructor of cache the cacheSize is computed as:
If this cacheSize is larger than 0, then used in
This ByteBuffer is then converted to a longBuffer using:
Assume that the ByteBuffer is generated (cacheSize is larger than 0), then replacing the cacheSize formula in the ByteBuffer allocation, you get this:
Assume cachePercent is 1:
The error happens when the ByteBuffer generated by
For example, 100 bytes:
For example, 799 bytes:
No problem, 800 or more bytes:
When using cachePercent of 2, it goes wrong up until 399 bytes:
Errors (anything less than 8)
Edit: It can also fail when the buffer is resized when calling
A workaround is too disable the cache (cachePercent 0), use a cachePercent of at least 8, or not use small files. A fix would probably be to check for a too small cacheSize (< 8 ), and allocate at least 8 bytes in that case.
The text was updated successfully, but these errors were encountered: