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 1804adb63945639f509ef0bccf9c5bd528395191
parent d9e052b594b1fa87bf639a1b167b8c26dd532513
Author: mauricefisher64 <92736594+mauricefisher64@users.noreply.github.com>
Date:   Thu, 13 Jul 2023 12:12:33 -0400

Fix iloc extent_offsets when offset_size is 0 (#277)


Diffstat:
Msdk/src/asset_handlers/bmff_io.rs | 51++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/sdk/src/asset_handlers/bmff_io.rs b/sdk/src/asset_handlers/bmff_io.rs @@ -826,7 +826,8 @@ fn adjust_known_offsets<W: Write + CAIRead>( None }; - let _extent_offset = match offset_size { + let extent_offset_file_pos = output.stream_position()?; + let extent_offset = match offset_size { 0 => 0_u64, 4 => output.read_u32::<BigEndian>()? as u64, 8 => output.read_u64::<BigEndian>()?, @@ -837,6 +838,54 @@ fn adjust_known_offsets<W: Write + CAIRead>( } }; + // no base offset so just adjust the raw extent_offset value + if constuction_method == 0 && base_offset == 0 && extent_offset != 0 { + output.seek(SeekFrom::Start(extent_offset_file_pos))?; + match offset_size { + 4 => { + let new_offset = if adjust < 0 { + extent_offset as u32 + - u32::try_from(adjust.abs()).map_err(|_| { + Error::InvalidAsset( + "Bad BMFF offset adjustment".to_string(), + ) + })? + } else { + extent_offset as u32 + + u32::try_from(adjust).map_err(|_| { + Error::InvalidAsset( + "Bad BMFF offset adjustment".to_string(), + ) + })? + }; + output.write_u32::<BigEndian>(new_offset)?; + } + 8 => { + let new_offset = if adjust < 0 { + extent_offset + - u64::try_from(adjust.abs()).map_err(|_| { + Error::InvalidAsset( + "Bad BMFF offset adjustment".to_string(), + ) + })? + } else { + extent_offset + + u64::try_from(adjust).map_err(|_| { + Error::InvalidAsset( + "Bad BMFF offset adjustment".to_string(), + ) + })? + }; + output.write_u64::<BigEndian>(new_offset)?; + } + _ => { + return Err(Error::InvalidAsset( + "Bad BMFF: unknown extent_offset format".to_string(), + )) + } + } + } + let _extent_length = match length_size { 0 => 0_u64, 4 => output.read_u32::<BigEndian>()? as u64,