Repository navigation
Fixed issue with BigTiff vs non-BigTiff offset value packing - #2247
Merged
Merged
Conversation
Contributor
|
👍 |
echeipesh
approved these changes
Jun 22, 2017
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.
Fixes #2241
The TIFF Spec has a condition that is an optimization, but has caused a lot of issues.
A TIFF-tag is structured like
[code, type, length, offset]. Thecodedetermines what tag it is, thetypeis the datatype such as Byte or Double, thelengthis the number of elements in the array of values, and theoffsetis the offset in the file where the values live.If the value of the data is a small size, the value can be packed into the space that stores the offset. In this way, the tiff tag reads as
[code, type, length, value]instead. This only happens if the byte size oftype, multiplied by thelengthof the data, is less than the byte size of theoffsetvalue. In the regular TIFF case, the offset is a 4-byte wideInt, so any value that can be stored in 4 or less bytes is stored in the offset field, instead of some other location in the file which is pointed to by the value in theoffsetfield.For BigTiff, the offset field is an 8-byte wide
Longvalue. We accounted for this when we first implemented bigtiffs. However, we didn't account for the changes in the packing mechanism: now if the value of the tag is less than or equal to 8 bytes, that value can be packed into the offset field of the tiff tag. The problem with not catching this packing is that, if you don't know the offset actually refers to a packed value, then you read that value as an offset into the file. For many cases this will be a very large number that will point to some huge offset in the file that doesn't actually exist; this is where the strange errors around BigTiff tag reading were coming from.This PR fixes this. The architecture of how we were utilizing implicit classes to add method extensions to ByteReader for reading arrays is clever but a bit unmalleable (I might have designed it, or at least didn't change it in the past, so that's on me). The type class I introduced was the least invasive way to implement this that I could think of; perhaps not perfect but it gets the job done. It changes technically
publicAPI, but in reality the API is internal enough that I can't imagine the change effecting any users (though I will note the API change in the CHANGELOG)