code works for intact gif files but not for corrupted