Don't crash on a malformed HEIC file - #262
Open
eeshsaxena wants to merge 1 commit into
Open
Conversation
process_file could raise NotImplementedError (an ISO-BMFF box with size 0), EOFError (a box running past the end of the file), or BadSize / BoxVersion -- none of which process_file caught, so a malformed HEIC crashed the caller instead of returning no tags. - next_box raises BadSize for a size-0 box instead of a bare NotImplementedError. - get() raises BadSize on an unexpected end of file instead of EOFError. - process_file catches the base ExifError, so every exif-py parse error (ExifNotFound, InvalidExif, BadSize, BoxVersion) yields an empty result. Added a test with several malformed HEIC inputs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
process_fileon a malformed HEIC can escape with an exception it doesn't handle, so the caller crashes instead of getting an empty result the way it does for other unreadable images:The HEIC reader raises a few things
process_filedoesn't catch: a bareNotImplementedErrorfor a size-0 box,EOFErrorfromget()at end of file, andBadSize/BoxVersion(which subclassExifErrorbut notInvalidExif).This keeps everything inside exif-py's own error hierarchy and handles it in one place:
next_boxraisesBadSizefor a size-0 box instead ofNotImplementedError.get()raisesBadSizeon an unexpected end of file instead ofEOFError.process_filecatches the baseExifError, soExifNotFound,InvalidExif,BadSizeandBoxVersionall yield an empty result.Valid files are unaffected (the existing suite passes, 32). Added a test with several malformed HEIC inputs. This is separate from the non-ASCII box-type case in #245 (that raises
UnicodeDecodeError, addressed in #253).