Fixes crashes due to length exceeding buffer.