c2pa-rs

A fork of https://github.com/contentauth/c2pa-rs/
git clone git://archive.git.mtrnord.blog/mtrnords-photography-manager/c2pa-rs.git
Log | Files | Refs | README

commit f8c9be35af153d539486d86707da7a86a7c99f07
parent 8764c543190d13eeaf96a7165e482fc207d54a3d
Author: mauricefisher64 <92736594+mauricefisher64@users.noreply.github.com>
Date:   Wed, 22 May 2024 13:43:52 -0400

Allow empty Merkle proof for last leaf node. (#470)


Diffstat:
Msdk/src/assertions/bmff_hash.rs | 19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/sdk/src/assertions/bmff_hash.rs b/sdk/src/assertions/bmff_hash.rs @@ -164,12 +164,15 @@ impl MerkleMap { location: u32, proof: &Option<VecByteBuf>, ) -> bool { + if location >= self.count { + return false; + } + let mut index = location; let mut hash = hash.to_vec(); + let layers = C2PAMerkleTree::to_layout(self.count as usize); if let Some(hashes) = proof { - let layers = C2PAMerkleTree::to_layout(self.count as usize); - // playback proof let mut proof_index = 0; for layer in layers { @@ -201,6 +204,14 @@ impl MerkleMap { index /= 2; } + } else { + //empty proof playback + for layer in layers { + if layer == self.hashes.len() { + break; + } + index /= 2; + } } self.hash_check(index, &hash) @@ -408,6 +419,10 @@ impl BmffHash { if let Some(pos) = boxes.iter().position(|b| b.path == "moof") { let mut box_list = vec![boxes[pos].clone()]; + if pos == 0 { + return moof_list; // this does not contain fragmented content + } + for b in boxes[pos + 1..].iter() { if b.path == "moof" { moof_list.push(box_list); // save box list