Skip to content

Commit

Permalink
PayloadWriter: Only set data_offset for operations that reference blobs
Browse files Browse the repository at this point in the history
This is never encountered when patching a file because avbroot only
produces REPLACE_XZ operations, but we should ensure valid outputs in
all scenarios.

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Sep 7, 2023
1 parent f93dc55 commit 34a5730
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions avbroot/src/format/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,10 @@ impl<W: Write> PayloadWriter<W> {
// The blob must contain all data in sequential order with no gaps.
for p in &mut header.manifest.partitions {
for op in &mut p.operations {
op.data_offset = Some(blob_size);

if let Some(length) = op.data_length {
// The field must be left unset when the blob contains no
// data for the operation.
op.data_offset = Some(blob_size);
blob_size += length;
}
}
Expand Down Expand Up @@ -402,7 +403,8 @@ impl<W: Write> PayloadWriter<W> {
/// [`InstallOperation::data_length`].
pub fn begin_next_operation(&mut self) -> Result<bool> {
if let Some(operation) = self.operation() {
// ZERO/DISCARD operations will not have a length.
// Only operations that reference data in the blob will have a
// length set.
if self.written < operation.data_length.unwrap_or(0) {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
Expand Down

0 comments on commit 34a5730

Please sign in to comment.