How to handle a corrupted image file