Off by one error in seekBinNoExpand
If seekBinNoExpand
is called with an offset equal to the buffer size then the function panics.
However, putPrim
only expands the buffer in the case that the offset plus the size is strictly greater than the buffer size.
Therefore if you end up writing exactly up to the buffer size and then moving to the end you will get a panic.
I imagine the following program exhibits the failure more directly.
bh <- openBinMem 0
bp <- tellBin @() bh
seekBinNoExpand bh bp
In general seekBinNoExpand
with the result of tellBin
should always succeed.
It might seem surprising this hasn't been discovered before but
- The initial buffer when writing an interface is 1mb, almost all interfaces are smaller than this.
- lazyPut/lazyGet and other functions which call seekBinNoExpand are not used very often.
The fix is simple, replace >=
with >
in seekBin
and seekBinNoExpand
.
Edited by Matthew Pickering