Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ rust-version = "1.82" # MSRV
libc = "0.2"
libbz2-rs-sys = { path = "libbz2-rs-sys/", default-features = false }

[profile.relwithdebinfo]
inherits = "release"
debug = true

[package]
name = "libbzip2-rs"
readme.workspace = true
Expand Down
90 changes: 37 additions & 53 deletions libbz2-rs-sys/src/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,75 +752,59 @@ pub(crate) fn decompress(
current_block = Block24;
}
}
match current_block {
Block24 => {
if zn > 20 {

macro_rules! get_next_sym {
($next_block:ident) => {
if (zn > 20/* the longest code */) {
error!(BZ_DATA_ERROR);
} else if zvec <= s.limit[usize::from(gSel)][zn as usize] {
let index = zvec - s.base[usize::from(gSel)][zn as usize];
nextSym = match s.perm[usize::from(gSel)].get(index as usize) {
match s.perm[usize::from(gSel)].get(index as usize) {
Some(&nextSym) => nextSym,
None => error!(BZ_DATA_ERROR),
};
}
} else {
zn += 1;
current_block = BZ_X_MTF_6;
continue;
current_block = $next_block;
continue 'c_10064;
}
};
}

match current_block {
Block24 => {
nextSym = get_next_sym!(BZ_X_MTF_6);
current_block = Block40;
}
Block52 => {
if zn > 20 {
error!(BZ_DATA_ERROR);
} else if zvec <= s.limit[usize::from(gSel)][zn as usize] {
let index = zvec - s.base[usize::from(gSel)][zn as usize];
nextSym = match s.perm[usize::from(gSel)].get(index as usize) {
Some(&nextSym) => nextSym,
None => error!(BZ_DATA_ERROR),
};
if nextSym == BZ_RUNA || nextSym == BZ_RUNB {
current_block = Block46;
} else {
let uc = s.seqToUnseq[s.mtfa[s.mtfbase[0_usize] as usize] as usize];
s.unzftab[usize::from(uc)] += es as i32;
match s.smallDecompress {
DecompressMode::Small => {
match ll16.get_mut(nblock as usize..(nblock + es) as usize) {
Some(slice) => slice.fill(u16::from(uc)),
None => error!(BZ_DATA_ERROR),
};
nblock += es;
}
DecompressMode::Fast => {
match tt.get_mut(nblock as usize..(nblock + es) as usize) {
Some(slice) => slice.fill(u32::from(uc)),
None => error!(BZ_DATA_ERROR),
};
nblock += es;
}
nextSym = get_next_sym!(BZ_X_MTF_4);

if nextSym == BZ_RUNA || nextSym == BZ_RUNB {
current_block = Block46;
} else {
let uc = s.seqToUnseq[s.mtfa[s.mtfbase[0_usize] as usize] as usize];
s.unzftab[usize::from(uc)] += es as i32;
match s.smallDecompress {
DecompressMode::Small => {
match ll16.get_mut(nblock as usize..(nblock + es) as usize) {
Some(slice) => slice.fill(u16::from(uc)),
None => error!(BZ_DATA_ERROR),
};
nblock += es;
}
DecompressMode::Fast => {
match tt.get_mut(nblock as usize..(nblock + es) as usize) {
Some(slice) => slice.fill(u32::from(uc)),
None => error!(BZ_DATA_ERROR),
};
nblock += es;
}
current_block = Block40;
}
} else {
zn += 1;
current_block = BZ_X_MTF_4;
continue;
current_block = Block40;
}
}
Block56 => {
if zn > 20 {
error!(BZ_DATA_ERROR);
} else if zvec <= s.limit[usize::from(gSel)][zn as usize] {
let index = zvec - s.base[usize::from(gSel)][zn as usize];
nextSym = match s.perm[usize::from(gSel)].get(index as usize) {
Some(&nextSym) => nextSym,
None => error!(BZ_DATA_ERROR),
};
} else {
zn += 1;
current_block = BZ_X_MTF_2;
continue;
}
nextSym = get_next_sym!(BZ_X_MTF_2);
current_block = Block40;
}
_ => {}
Expand Down