Prevent segfaults on malformed images