Fix PR2423 by checking all indices for out of range access, not only