Repository navigation
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.
Add strip offsets and byte counts as uint32_t in GetImageData, as C++ does
Problem
GetImageData(C++, Rust) finds a directory's image. For a strip image, it checks that each strip starts where the previous one ends, and adds up the byte counts to get the image's length. C++ does both inuint32_t, so the check and the sum wrap around past 2^32-1. The port adds withchecked_addin the check and the sum, and rejects the image when either overflows. For example, a DNG whose IFD0 holds a 16×12 RGB thumbnail at offset 206, with only IFD0's StripOffsets and StripByteCounts changed:With one strip (StripOffsets 206, StripByteCounts 576), or two strips that do not wrap (206, 506; 300, 276), both return the 16×12 thumbnail, 576 bytes at 206.
Question
Which behaviour do we want: C++'s or the Rust port's? Specifically, when a strip image's offsets and byte counts pass 2^32-1 when added, should
GetImageDataadd them asuint32_tand keep the image (like the C++ library), or reject the image (like the Rust port)?This PR implements C++'s behaviour.
Fix
offsets_are_consecutiveandget_image_dataadd withwrapping_add, as C++'suint32_tadditions do:offsets_are_consecutivecompares the wrapped sum with the next offset, as C++ does.get_image_dataadds the byte counts with wrapping, as C++'sstd::accumulateover0Udoes. The examples above then match C++.Replayed before and after:
Notes for review:
checked_add.GetImageData: DNG, NEF, ORF, PEF and the rest. The port's tests pass unchanged (44 + 174).