fix READ_LENGTH() and WRITE_LENGTH() bug