Fix incorrect memory sizing in chunked buffer allocation.
Improved fix for off-by-one buffer overflow.