iobuffer: fix overflow OOB read/write bugs (#59728)
maxsize is usually typemax, so need to be careful to not do comparisons
after adding to it. Substracting from it should normally be perfectly
fine. At worst we should compute a negative amount of space remaining.