Fixes handling of corrupted files

Fixes failure on invalid filter type.
Adds error handling for IHDR and PLTE parsing.