Fixed an subtle issue causing files with certain Unicode characters not be found from a ZipFile #6
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.
There is a subtle issue in ZipFile.m with how the file contents dictionary is parsed for -initWithFileName:mode: and then queried in -locateFileInZip: . If -locateFileInZip: is called with a string that uses a different Unicode normalization form than what was used to encode the file names and used as the key in the contents dictionary, the file info object is not found (the ZipFile 'contents' dictionary would have its keys in a different Unicode normalisation form).
To give an example, here are two strings which look exactly similar to the eye but have different hash codes (and therefore different keys in an NSDictionary):
(gdb) print (NSUInteger)[@"Contents/Resources/N. Engl. J. Med. 2009 Hütter.pdf" hash]
$5 = 523423533613971934
(gdb) print (NSUInteger)[@"Contents/Resources/N. Engl. J. Med. 2009 Hütter.pdf" hash]
$6 = 13774458812937735516
In an error case I encountered, the string I received from another component in the application uses the 2nd kind of representation, whereas Objective-Zip the first kind. Requiring a certain Unicode normalization form as arguments given to -locateFileInZip: is not practical, therefore my suggested solution uses uses the Normalization Form D as the 'contents' dictionary keys (the file info 'name' strings), and converts the string given as an argument to -locateFileInZip: to this same form.