Add a nil guard to prevent crashes when a link's media type cannot be parsed - #324
Open
leonardr wants to merge 5 commits into
Open
Add a nil guard to prevent crashes when a link's media type cannot be parsed#324leonardr wants to merge 5 commits into
leonardr wants to merge 5 commits into
Conversation
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.
This branch fixes a problem I've seen in real EPUBs (sample available on request) which causes a crash on load.
The problem is triggered by a link in the OPF with a media type that causes mediatype.New to error; in my case it was "application/application/x-font-ttf". The Link object ends up with a nil
MediaType. There are a number of places in the code that call functions onlink.MediaTypewithout a nil guard, which causes the crash..In this branch I added nil guards everywhere in the code I think is relevant. The end result should be that a link with a nil media type is not anything in particular: not a bitmap, not HTML, etc.
An alternative implementation would be to define a sentinel "unknown"
MediaTypeto stand in for the case wheremediatype.Newcan't parse the actual media type. Then we can guaranteemediatype.Newalways returns aMediaTypeand the nil guards won't be necessary. That's a more systematic change, so before working on it, I want to understand your general policy on having go-toolkit handle invalid data in EPUBs.