Skip to content

Commit

Permalink
Switch from xz2 to liblzma
Browse files Browse the repository at this point in the history
liblzma is a maintained fork of xz2. We can now get rid of our own fork
of xz2.

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Dec 31, 2023
1 parent 9ef5629 commit 0a68966
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 45 deletions.
50 changes: 31 additions & 19 deletions Cargo.lock

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

11 changes: 2 additions & 9 deletions avbroot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ctrlc = "3.4.0"
flate2 = "1.0.27"
gf256 = { version = "0.3.0", features = ["rs"] }
hex = { version = "0.4.3", features = ["serde"] }
liblzma = "0.2.1"
lz4_flex = "0.11.1"
memchr = "2.6.0"
num-bigint-dig = "0.8.4"
Expand Down Expand Up @@ -59,14 +60,6 @@ x509-cert = { version = "0.2.4", features = ["builder"] }
git = "https://github.com/jongiddy/bzip2-rs"
rev = "2aefcb4d3634de1df226c73d93f758d65228bb8c"

# The upstream xz2 crate uses an old version of liblzma when compiling with the
# `static` feature and doesn't enable all of the encoders and decoders. This
# causes certain payload data to fail to decompress.
# https://github.com/chenxiaolong/avbroot/issues/138
[dependencies.xz2]
git = "https://github.com/chenxiaolong/xz2-rs"
rev = "fe2050b9c3395db15d8610f1dabb505440c1a556"

# https://github.com/zip-rs/zip/pull/383
[dependencies.zip]
git = "https://github.com/chenxiaolong/zip"
Expand All @@ -85,4 +78,4 @@ protox = "0.5.0"
assert_matches = "1.5.0"

[features]
static = ["bzip2/static", "xz2/static"]
static = ["bzip2/static", "liblzma/static"]
10 changes: 5 additions & 5 deletions avbroot/src/format/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use std::io::{self, Read, Seek, Write};

use byteorder::{LittleEndian, WriteBytesExt};
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
use lz4_flex::frame::FrameDecoder;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use xz2::{
use liblzma::{
read::XzDecoder,
stream::{Check, Stream},
write::XzEncoder,
};
use lz4_flex::frame::FrameDecoder;
use serde::{Deserialize, Serialize};
use thiserror::Error;

static GZIP_MAGIC: &[u8; 2] = b"\x1f\x8b";
static LZ4_LEGACY_MAGIC: &[u8; 4] = b"\x02\x21\x4c\x18";
Expand All @@ -25,7 +25,7 @@ pub enum Error {
#[error("Unknown compression format")]
UnknownFormat,
#[error("XZ stream error")]
XzStream(#[from] xz2::stream::Error),
XzStream(#[from] liblzma::stream::Error),
#[error("I/O error")]
Io(#[from] io::Error),
}
Expand Down
12 changes: 6 additions & 6 deletions avbroot/src/format/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ use base64::engine::general_purpose::STANDARD;
use base64::Engine;
use byteorder::{BigEndian, ReadBytesExt};
use bzip2::write::BzDecoder;
use liblzma::{
stream::{Check, Stream},
write::XzDecoder,
write::XzEncoder,
};
use num_traits::ToPrimitive;
use prost::Message;
use rayon::{
Expand All @@ -25,11 +30,6 @@ use rsa::{traits::PublicKeyParts, Pkcs1v15Sign, RsaPrivateKey};
use sha2::Sha256;
use thiserror::Error;
use x509_cert::Certificate;
use xz2::{
stream::{Check, Stream},
write::XzDecoder,
write::XzEncoder,
};

use crate::{
crypto,
Expand Down Expand Up @@ -99,7 +99,7 @@ pub enum Error {
#[error("Failed to decode protobuf message")]
ProtobufDecode(#[from] prost::DecodeError),
#[error("XZ stream error")]
XzStream(#[from] xz2::stream::Error),
XzStream(#[from] liblzma::stream::Error),
#[error("RSA error")]
Rsa(#[from] rsa::Error),
#[error("I/O error")]
Expand Down
10 changes: 5 additions & 5 deletions avbroot/src/patch/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ use std::{
};

use bstr::ByteSlice;
use liblzma::{
stream::{Check, Stream},
write::XzEncoder,
};
use rayon::iter::{IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelIterator};
use regex::bytes::Regex;
use ring::digest::Context;
use rsa::RsaPrivateKey;
use thiserror::Error;
use x509_cert::Certificate;
use xz2::{
stream::{Check, Stream},
write::XzEncoder,
};
use zip::{result::ZipError, ZipArchive};

use crate::{
Expand Down Expand Up @@ -67,7 +67,7 @@ pub enum Error {
#[error("OTA certificate error")]
OtaCert(#[from] otacert::Error),
#[error("XZ stream error")]
XzStream(#[from] xz2::stream::Error),
XzStream(#[from] liblzma::stream::Error),
#[error("Zip error")]
Zip(#[from] ZipError),
#[error("I/O error")]
Expand Down
3 changes: 2 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ include-workspace = true
bypass = [
# Copies of unmodified crashwrangler objects for old macOS versions.
{ name = "honggfuzz", allow-globs = ["honggfuzz/third_party/mac/CrashReport_*.o"] },
# Test files for liblzma's test suite
{ name = "liblzma-sys", allow-globs = ["xz/tests/compress_prepared_bcj_*"] },
]

[sources]
unknown-registry = "deny"
unknown-git = "deny"
allow-git = [
"https://github.com/chenxiaolong/xz2-rs",
"https://github.com/chenxiaolong/zip",
"https://github.com/jongiddy/bzip2-rs",
]

0 comments on commit 0a68966

Please sign in to comment.