Skip to content

Commit a5611e5

Browse files
committed
Add a check during LZP decompression
1 parent 0816f4c commit a5611e5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/transform/LZCodec.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ bool LZXCodec<T>::forward(SliceArray<byte>& input, SliceArray<byte>& output, int
389389

390390
// Fill _hashes and update positions
391391
anchor = srcIdx + bestLen;
392-
prefetchRead(&src[anchor + 64]);
393-
prefetchRead(&src[anchor + 128]);
392+
prefetchRead(&src[anchor]);
394393

395394
while (srcIdx + 4 < anchor) {
396395
srcIdx += 4;
@@ -493,8 +492,8 @@ bool LZXCodec<T>::inverseV6(SliceArray<byte>& input, SliceArray<byte>& output, i
493492
bool res = true;
494493
int srcIdx = 13;
495494
int dstIdx = 0;
496-
int repd0 = 0;
497-
int repd1 = 0;
495+
int repd0 = count;
496+
int repd1 = count;
498497

499498
while (true) {
500499
const int token = int(src[tkIdx++]);
@@ -848,6 +847,7 @@ bool LZPCodec::inverse(SliceArray<byte>& input, SliceArray<byte>& output, int co
848847
return false;
849848

850849
const int srcEnd = count;
850+
const int dstEnd = output._length;
851851
const byte* src = &input._array[input._index];
852852
byte* dst = &output._array[output._index];
853853

@@ -899,6 +899,9 @@ bool LZPCodec::inverse(SliceArray<byte>& input, SliceArray<byte>& output, int co
899899
mLen += int(src[srcIdx++]);
900900
const int mEnd = dstIdx + mLen;
901901

902+
if (mEnd > dstEnd)
903+
return false;
904+
902905
if (dstIdx >= ref + 8) {
903906
do {
904907
// No overlap

0 commit comments

Comments
 (0)