Fix bug where dirty bounds are out of the image bounds