fix memory access out of image metadata bounds