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.
Keep a CR3 box's size and end in usize on 32-bit targets, as GetNextBox does
Problem
GetNextBox(C++, Rust) reads a CR3 box's header: a 32-bit size, a tag, and a 64-bit size after the tag when the 32-bit size is 1. C++ holds the size in asize_tand checks the box's end against the largestsize_t. The port holds the size and the end in au64. On a 64-bit target, the two agree. On a 32-bit target, wheresize_tis 32 bits, C++ differs in two ways:The port reads both boxes on either target.
For example, a CR3 from the campaigns where the box right after
stsd's header, whereProcessStblBoxlooks for CRAW, is not CRAW and has a 32-bit size of 1 and a 64-bit size of 0x5700000000000000.ProcessStblBoxskips a box there that is not CRAW, but fails on one that is not a valid box. On x86-64, C++ keeps the whole size, skips the box and returns the 1620×1080 preview from the PRVW box. On 32-bit ARM, the low 32 bits are 0, so C++ rejects the box andGetPreviewImageDatareturns kFail. With the box's 32-bit size set to 0xFFFFFF00 instead, the box (at byte 400) ends at byte 4,294,967,440, and C++ on 32-bit ARM rejects it too:With a 64-bit size whose low 32 bits are 32, or a 32-bit size of 0xFFFFFE00 (which ends before 2^32), both targets give the preview.
Question
Which behaviour do we want: C++'s or the Rust port's? Specifically, on a 32-bit target:
GetNextBoxkeep only the size's low 32 bits (like the C++ library), or the whole size (like the Rust port)?GetNextBoxreject the box (like the C++ library), or read it (like the Rust port)?This PR implements C++'s behaviour.
Fix
In
read_next_box, the port now keeps the size and the box's end inusize, as C++ keeps them insize_t:length_64 as usize, the low 32 bits on a 32-bit target, as C++ does.usize, so it rejects a box that ends pastusize::MAX, as C++ does.The examples above then match C++. Replayed on 32-bit ARM, before and after:
Notes for review:
test_read_next_box_clean_eof_handlingandtest_piex_stream_t_layoutfail there on master already, and the same way with this PR.