fixed bug reading data buffer outside bounds