Skip to content

Commit 8f9c19f

Browse files
bjorn3folkertdev
authored andcommitted
Pass slice for litPtr to ZSTDv07_execSequence
1 parent b7e31ee commit 8f9c19f

File tree

1 file changed

+13
-40
lines changed

1 file changed

+13
-40
lines changed

lib/legacy/zstd_v07.rs

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,13 +1611,9 @@ static OF_defaultNorm: [i16; 29] = [
16111611
static OF_defaultNormLog: u32 = 5;
16121612
const WILDCOPY_OVERLENGTH: usize = 8;
16131613
#[inline]
1614-
unsafe fn ZSTDv07_wildcopy(
1615-
dst: *mut core::ffi::c_void,
1616-
src: *const core::ffi::c_void,
1617-
length: isize,
1618-
) {
1619-
let mut ip = src as *const u8;
1620-
let mut op = dst as *mut u8;
1614+
unsafe fn ZSTDv07_wildcopy(dst: *mut u8, src: *const u8, length: isize) {
1615+
let mut ip = src;
1616+
let mut op = dst;
16211617
let oend = op.offset(length);
16221618
loop {
16231619
core::ptr::copy_nonoverlapping(ip, op, 8);
@@ -2192,8 +2188,7 @@ fn ZSTDv07_decodeSequence(seqState: &mut seqState_t) -> seq_t {
21922188
unsafe fn ZSTDv07_execSequence(
21932189
mut dst: Writer<'_>,
21942190
mut sequence: seq_t,
2195-
litPtr: &mut *const u8,
2196-
litLimit: *const u8,
2191+
litPtr: &mut &[u8],
21972192
base: *const u8,
21982193
vBase: *const u8,
21992194
dictEnd: *const u8,
@@ -2206,24 +2201,19 @@ unsafe fn ZSTDv07_execSequence(
22062201
let sequenceLength = sequence.litLength + sequence.matchLength;
22072202
let oMatchEnd = op.add(sequenceLength);
22082203
let oend_w = oend.wrapping_sub(WILDCOPY_OVERLENGTH);
2209-
let iLitEnd = (*litPtr).add(sequence.litLength);
22102204
let mut match_0: *const u8 = oLitEnd.wrapping_sub(sequence.offset);
22112205
if (sequence.litLength).wrapping_add(WILDCOPY_OVERLENGTH) > oend.offset_from_unsigned(op) {
22122206
return Err(Error::dstSize_tooSmall);
22132207
}
22142208
if sequenceLength > oend.offset_from_unsigned(op) {
22152209
return Err(Error::dstSize_tooSmall);
22162210
}
2217-
if sequence.litLength > litLimit.offset_from_unsigned(*litPtr) {
2211+
if sequence.litLength > litPtr.len() {
22182212
return Err(Error::corruption_detected);
22192213
}
2220-
ZSTDv07_wildcopy(
2221-
op as *mut core::ffi::c_void,
2222-
*litPtr as *const core::ffi::c_void,
2223-
sequence.litLength as isize,
2224-
);
2214+
ZSTDv07_wildcopy(op, (*litPtr).as_ptr(), sequence.litLength as isize);
22252215
op = oLitEnd;
2226-
*litPtr = iLitEnd;
2216+
*litPtr = &litPtr[sequence.litLength..];
22272217
if sequence.offset > oLitEnd.offset_from_unsigned(base) {
22282218
if sequence.offset > oLitEnd.offset_from_unsigned(vBase) {
22292219
return Err(Error::corruption_detected);
@@ -2267,11 +2257,7 @@ unsafe fn ZSTDv07_execSequence(
22672257
match_0 = match_0.add(8);
22682258
if oMatchEnd > oend.offset(-((16 - MINMATCH) as isize)) {
22692259
if op < oend_w {
2270-
ZSTDv07_wildcopy(
2271-
op as *mut core::ffi::c_void,
2272-
match_0 as *const core::ffi::c_void,
2273-
oend_w.offset_from(op),
2274-
);
2260+
ZSTDv07_wildcopy(op, match_0, oend_w.offset_from(op));
22752261
match_0 = match_0.offset(oend_w.offset_from(op));
22762262
op = oend_w;
22772263
}
@@ -2283,11 +2269,7 @@ unsafe fn ZSTDv07_execSequence(
22832269
*fresh45 = *fresh44;
22842270
}
22852271
} else {
2286-
ZSTDv07_wildcopy(
2287-
op as *mut core::ffi::c_void,
2288-
match_0 as *const core::ffi::c_void,
2289-
sequence.matchLength as isize - 8,
2290-
);
2272+
ZSTDv07_wildcopy(op, match_0, sequence.matchLength as isize - 8);
22912273
}
22922274
Ok(sequenceLength)
22932275
}
@@ -2299,8 +2281,7 @@ fn ZSTDv07_decompressSequences(
22992281
let mut ip = seqStart;
23002282
let dst_capacity = dst.capacity();
23012283
let mut op = dst;
2302-
let mut litPtr = dctx.litPtr;
2303-
let litEnd = unsafe { litPtr.add(dctx.litSize) };
2284+
let mut litPtr = unsafe { core::slice::from_raw_parts(dctx.litPtr, dctx.litSize) };
23042285
let DTableLL = &mut dctx.LLTable;
23052286
let DTableML = &mut dctx.MLTable;
23062287
let DTableOffb = &mut dctx.OffTable;
@@ -2337,15 +2318,7 @@ fn ZSTDv07_decompressSequences(
23372318
nbSeq -= 1;
23382319
let sequence = ZSTDv07_decodeSequence(&mut seqState);
23392320
let oneSeqSize = unsafe {
2340-
ZSTDv07_execSequence(
2341-
op.subslice(..),
2342-
sequence,
2343-
&mut litPtr,
2344-
litEnd,
2345-
base,
2346-
vBase,
2347-
dictEnd,
2348-
)?
2321+
ZSTDv07_execSequence(op.subslice(..), sequence, &mut litPtr, base, vBase, dictEnd)?
23492322
};
23502323
op = op.subslice(oneSeqSize..);
23512324
}
@@ -2354,12 +2327,12 @@ fn ZSTDv07_decompressSequences(
23542327
}
23552328
dctx.rep = core::array::from_fn(|i| seqState.prevOffset[i] as u32);
23562329
}
2357-
let lastLLSize = unsafe { litEnd.offset_from_unsigned(litPtr) };
2330+
let lastLLSize = litPtr.len();
23582331
if lastLLSize > op.capacity() {
23592332
return Err(Error::dstSize_tooSmall);
23602333
}
23612334
if lastLLSize > 0 {
2362-
unsafe { ptr::copy_nonoverlapping(litPtr, op.as_mut_ptr(), lastLLSize) };
2335+
unsafe { ptr::copy_nonoverlapping(litPtr.as_ptr(), op.as_mut_ptr(), lastLLSize) };
23632336
op = op.subslice(lastLLSize..);
23642337
}
23652338
Ok(dst_capacity - op.capacity())

0 commit comments

Comments
 (0)