Skip to content

Commit

Permalink
PayloadWriter: Don't set data_offset for ZERO and DISCARD operations
Browse files Browse the repository at this point in the history
`data_offset` should only be set if the operation references data in the
blob section of the payload. This is never encountered when patching a
file because avbroot does not produce ZERO/DISCARD 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 a46bc16
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion avbroot/src/format/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,15 @@ 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);
match op.type_pb {
mod_InstallOperation::Type::ZERO | mod_InstallOperation::Type::DISCARD => {
// The field must be left unset when the blob contains
// no data for the operation.
}
_ => {
op.data_offset = Some(blob_size);
}
}

if let Some(length) = op.data_length {
blob_size += length;
Expand Down

0 comments on commit a46bc16

Please sign in to comment.