[#1782] Fix IndexOutOfBoundException with direct buffer and gathering writes