Skip to content

Commit

Permalink
Fix data_len not found error on zero op (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Kartik Sharma <kartik.sharma522@gmail.com>
  • Loading branch information
ajeetdsouza and crazystylus authored Apr 21, 2023
1 parent b2b9294 commit 4fa3497
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name = "otadump"
repository = "https://github.com/crazystylus/otadump"
readme = "README.md"
rust-version = "1.68.0"
version = "0.1.1"
version = "0.1.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
45 changes: 26 additions & 19 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Cmd {
threadpool.scope(|scope| -> Result<()> {
let multiprogress = {
// Setting a fixed update frequence reduces flickering.
let draw_target = ProgressDrawTarget::stderr_with_hz(5);
let draw_target = ProgressDrawTarget::stderr_with_hz(2);
MultiProgress::with_draw_target(draw_target)
};
for update in manifest.partitions.iter().filter(|update| {
Expand Down Expand Up @@ -149,35 +149,24 @@ impl Cmd {
partition_len: usize,
block_size: usize,
) -> Result<()> {
let data_len = op.data_length.context("data_length not defined")? as usize;
let mut data = {
let offset = op.data_offset.context("data_offset not defined")? as usize;
payload
.data
.get(offset..offset + data_len)
.context("data offset exceeds payload size")?
};
match &op.data_sha256_hash {
Some(hash) if !self.no_verify => {
self.verify_sha256(data, hash).context("input verification failed")?;
}
_ => {}
}

let mut dst_extents = self
.extract_dst_extents(op, partition, partition_len, block_size)
.context("error extracting dst_extents")?;

match Type::from_i32(op.r#type) {
Some(Type::Replace) => self
.run_op_replace(&mut data, &mut dst_extents, block_size)
.context("error in REPLACE operation"),
Some(Type::Replace) => {
let mut data = self.extract_data(op, payload).context("error extracting data")?;
self.run_op_replace(&mut data, &mut dst_extents, block_size)
.context("error in REPLACE operation")
}
Some(Type::ReplaceBz) => {
let data = self.extract_data(op, payload).context("error extracting data")?;
let mut decoder = BzDecoder::new(data);
self.run_op_replace(&mut decoder, &mut dst_extents, block_size)
.context("error in REPLACE_BZ operation")
}
Some(Type::ReplaceXz) => {
let data = self.extract_data(op, payload).context("error extracting data")?;
let mut decoder = LzmaReader::new_decompressor(data)
.context("unable to initialize lzma decoder")?;
self.run_op_replace(&mut decoder, &mut dst_extents, block_size)
Expand Down Expand Up @@ -246,6 +235,24 @@ impl Cmd {
Ok((partition, partition_len as usize))
}

fn extract_data<'a>(&self, op: &InstallOperation, payload: &'a Payload) -> Result<&'a [u8]> {
let data_len = op.data_length.context("data_length not defined")? as usize;
let data = {
let offset = op.data_offset.context("data_offset not defined")? as usize;
payload
.data
.get(offset..offset + data_len)
.context("data offset exceeds payload size")?
};
match &op.data_sha256_hash {
Some(hash) if !self.no_verify => {
self.verify_sha256(data, hash).context("input verification failed")?;
}
_ => {}
}
Ok(data)
}

fn extract_dst_extents(
&self,
op: &InstallOperation,
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::all)]
mod chromeos_update_engine {
include!(concat!(env!("OUT_DIR"), "/chromeos_update_engine.rs"));
}
Expand Down

0 comments on commit 4fa3497

Please sign in to comment.