Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 8 additions & 7 deletions libbz2-rs-sys/src/bzlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,25 +522,26 @@ impl Ftab {
}
}

#[repr(C)]
pub(crate) struct DState {
pub strm_addr: usize, // Only for a consistency check
pub state: decompress::State,
pub state_out_ch: u8,
pub state_out_len: u32,
pub state_out_ch: u8,
pub blockRandomised: bool,
pub blockSize100k: u8,
pub k0: u8,
pub rNToGo: i32,
pub rTPos: i32,
pub bsBuff: u32,
pub bsLive: i32,
pub blockSize100k: i32,
pub smallDecompress: DecompressMode,
pub currBlockNo: i32,
pub verbosity: i32,
pub origPtr: i32,
pub tPos: u32,
pub k0: u8,
pub unzftab: [i32; 256],
pub nblock_used: i32,
pub unzftab: [i32; 256],
pub cftab: [i32; 257],
pub cftabCopy: [i32; 257],
pub tt: DSlice<u32>,
Expand Down Expand Up @@ -575,7 +576,7 @@ pub(crate) struct SaveArea {
pub EOB: u16,
pub groupNo: i32,
pub nblock: u32,
pub es: i32,
pub es: u32,
pub zvec: i32,
pub nextSym: u16,
pub nSelectors: u16,
Expand Down Expand Up @@ -1339,13 +1340,13 @@ fn un_rle_obuf_to_output_fast(strm: &mut BzStream<DState>, s: &mut DState) -> bo
let mut c_tPos: u32 = s.tPos;
let mut cs_next_out: *mut c_char = strm.next_out;
let mut cs_avail_out: c_uint = strm.avail_out;
let ro_blockSize100k: i32 = s.blockSize100k;
let ro_blockSize100k: u8 = s.blockSize100k;
/* end restore */

let avail_out_INIT: u32 = cs_avail_out;
let s_save_nblockPP: i32 = s.save.nblock as i32 + 1;

let tt = &s.tt.as_slice()[..100000usize.wrapping_mul(ro_blockSize100k as usize)];
let tt = &s.tt.as_slice()[..100000usize.wrapping_mul(usize::from(ro_blockSize100k))];

macro_rules! BZ_GET_FAST_C {
($c_tPos:expr) => {
Expand Down
61 changes: 26 additions & 35 deletions libbz2-rs-sys/src/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ pub(crate) fn decompress(
if current_block == BZ_X_MAGIC_4 {
s.state = State::BZ_X_MAGIC_4;

s.blockSize100k = GET_BYTE!(strm, s) as i32;
s.blockSize100k = GET_BYTE!(strm, s);

if !(b'1' as i32..=b'9' as i32).contains(&s.blockSize100k) {
if !(b'1'..=b'9').contains(&s.blockSize100k) {
error!(BZ_DATA_ERROR_MAGIC);
}

s.blockSize100k -= b'0' as i32;
s.blockSize100k -= b'0';

match s.smallDecompress {
DecompressMode::Small => {
Expand Down Expand Up @@ -592,7 +592,7 @@ pub(crate) fn decompress(
uc = GET_BYTE!(strm, s);

s.origPtr = s.origPtr << 8 | i32::from(uc);
if !(0..10 + 100000 * s.blockSize100k).contains(&s.origPtr) {
if !(0..10 + 100000 * i32::from(s.blockSize100k)).contains(&s.origPtr) {
error!(BZ_DATA_ERROR);
}

Expand Down Expand Up @@ -782,31 +782,24 @@ pub(crate) fn decompress(
if nextSym == BZ_RUNA || nextSym == BZ_RUNB {
current_block = Block46;
} else {
es += 1;
uc = s.seqToUnseq[s.mtfa[s.mtfbase[0_usize] as usize] as usize];
s.unzftab[uc as usize] += es;
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 => {
while es > 0 {
if nblock >= 100000 * nblockMAX100k as u32 {
error!(BZ_DATA_ERROR);
} else {
ll16[nblock as usize] = uc as u16;
nblock += 1;
es -= 1;
}
}
let ll16 = &mut ll16[..100000 * usize::from(nblockMAX100k)];
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 => {
while es > 0 {
if nblock >= 100000 * nblockMAX100k as u32 {
error!(BZ_DATA_ERROR);
} else {
tt[nblock as usize] = uc as u32;
nblock += 1;
es -= 1;
}
}
let tt = &mut tt[..100000 * usize::from(nblockMAX100k)];
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;
Expand Down Expand Up @@ -839,10 +832,10 @@ pub(crate) fn decompress(
if nextSym == EOB {
current_block = Block41;
} else if nextSym == BZ_RUNA || nextSym == BZ_RUNB {
es = -1;
es = 0;
logN = 0;
current_block = Block46;
} else if nblock >= 100000 * nblockMAX100k as u32 {
} else if nblock >= 100000 * u32::from(nblockMAX100k) {
error!(BZ_DATA_ERROR);
} else {
let uc = usize::from(initialize_mtfa(&mut s.mtfa, &mut s.mtfbase, nextSym));
Expand Down Expand Up @@ -886,6 +879,8 @@ pub(crate) fn decompress(
if s.verbosity >= 2 {
debug_log!("rt+rld");
}
let max_block_size =
100000_u32.wrapping_mul(u32::from(s.blockSize100k));
match s.smallDecompress {
DecompressMode::Small => {
// Make a copy of cftab, used in generation of T
Expand Down Expand Up @@ -941,8 +936,7 @@ pub(crate) fn decompress(
if s.blockRandomised {
s.rNToGo = 0;
s.rTPos = 0;
if s.tPos >= 100000_u32.wrapping_mul(s.blockSize100k as u32)
{
if s.tPos >= max_block_size {
// NOTE: this originates in the BZ_GET_FAST macro, and the
// `return true` is probably uninitentional?!
return ReturnCode::BZ_RUN_OK;
Expand All @@ -964,8 +958,7 @@ pub(crate) fn decompress(
s.rNToGo -= 1;
s.k0 ^= if s.rNToGo == 1 { 1 } else { 0 };
} else {
if s.tPos >= 100000_u32.wrapping_mul(s.blockSize100k as u32)
{
if s.tPos >= max_block_size {
// NOTE: this originates in the BZ_GET_FAST macro, and the
// `return true` is probably uninitentional?!
return ReturnCode::BZ_RUN_OK;
Expand All @@ -990,8 +983,7 @@ pub(crate) fn decompress(
if s.blockRandomised {
s.rNToGo = 0;
s.rTPos = 0;
if s.tPos >= 100000_u32.wrapping_mul(s.blockSize100k as u32)
{
if s.tPos >= max_block_size {
// NOTE: this originates in the BZ_GET_FAST macro, and the
// `return true` is probably uninitentional?!
return ReturnCode::BZ_RUN_OK;
Expand All @@ -1010,8 +1002,7 @@ pub(crate) fn decompress(
s.rNToGo -= 1;
s.k0 ^= if s.rNToGo == 1 { 1 } else { 0 };
} else {
if s.tPos >= 100000_u32.wrapping_mul(s.blockSize100k as u32)
{
if s.tPos >= max_block_size {
// NOTE: this originates in the BZ_GET_FAST macro, and the
// `return true` is probably uninitentional?!
return ReturnCode::BZ_RUN_OK;
Expand Down