Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix for overly harsh checks when checking Merkle trees. #289

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions sdk/src/assertions/bmff_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,33 +609,13 @@ impl BmffHash {
}
};

let sample_cnt = mp4.sample_count(mm.local_id).map_err(|_e| {
Error::InvalidAsset("Could not parse BMFF track sample".to_string())
})?;

let sample_cnt = track.sample_count();
if sample_cnt == 0 {
return Err(Error::InvalidAsset("No samples".to_string()));
}

let track_id = track.track_id();

// get the chunk count
let stbl_box = &track.trak.mdia.minf.stbl;
let chunk_cnt = match &stbl_box.stco {
Some(stco) => stco.entries.len(),
None => match &stbl_box.co64 {
Some(co64) => co64.entries.len(),
None => 0,
},
};

// the Merkle count is the number of chunks for timed media
if mm.count != chunk_cnt as u32 {
return Err(Error::HashMismatch(
"Track count does not match Merkle map count".to_string(),
));
}

// create sample to chunk mapping
// create the Merkle tree per samples in a chunk
let mut chunk_hash_map: HashMap<u32, Hasher> = HashMap::new();
Expand Down Expand Up @@ -684,19 +664,13 @@ impl BmffHash {
}
}

if chunk_cnt != chunk_hash_map.len() {
return Err(Error::HashMismatch(
"Incorrect number of Merkle trees".to_string(),
));
}

// finalize leaf hashes
let mut leaf_hashes = Vec::new();
for chunk_bmff_mm in &track_to_bmff_merkle_map[&track_id] {
match chunk_hash_map.remove(&(chunk_bmff_mm.location + 1)) {
Some(h) => {
let h = Hasher::finalize(h);
leaf_hashes.push(h.clone());
leaf_hashes.push(h);
}
None => {
return Err(Error::HashMismatch(
Expand Down