Skip to content

Commit ed38ff1

Browse files
committed
Merge tag 'zstd-linus-v6.3-rc3' of https://github.com/terrelln/linux
Pull zstd fixes from Nick Terrell: "A small number of fixes for zstd-v1.5.2. I'm not pulling in zstd-v1.5.4 from upstream this release because it didn't have any time to bake in linux-next, but I'm aiming for the next update in v6.4" * tag 'zstd-linus-v6.3-rc3' of https://github.com/terrelln/linux: zstd: Fix definition of assert() lib: zstd: Backport fix for in-place decompression lib: zstd: Fix -Wstringop-overflow warning
2 parents c0856b7 + 6906598 commit ed38ff1

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

lib/zstd/common/zstd_deps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static uint64_t ZSTD_div64(uint64_t dividend, uint32_t divisor) {
8484

8585
#include <linux/kernel.h>
8686

87-
#define assert(x) WARN_ON((x))
87+
#define assert(x) WARN_ON(!(x))
8888

8989
#endif /* ZSTD_DEPS_ASSERT */
9090
#endif /* ZSTD_DEPS_NEED_ASSERT */

lib/zstd/decompress/huf_decompress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ static void HUF_fillDTableX2Level2(HUF_DEltX2* DTable, U32 targetLog, const U32
985985

986986
static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog,
987987
const sortedSymbol_t* sortedList,
988-
const U32* rankStart, rankVal_t rankValOrigin, const U32 maxWeight,
988+
const U32* rankStart, rankValCol_t *rankValOrigin, const U32 maxWeight,
989989
const U32 nbBitsBaseline)
990990
{
991991
U32* const rankVal = rankValOrigin[0];

lib/zstd/decompress/zstd_decompress.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ static size_t ZSTD_copyRawBlock(void* dst, size_t dstCapacity,
798798
if (srcSize == 0) return 0;
799799
RETURN_ERROR(dstBuffer_null, "");
800800
}
801-
ZSTD_memcpy(dst, src, srcSize);
801+
ZSTD_memmove(dst, src, srcSize);
802802
return srcSize;
803803
}
804804

@@ -858,6 +858,7 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
858858

859859
/* Loop on each block */
860860
while (1) {
861+
BYTE* oBlockEnd = oend;
861862
size_t decodedSize;
862863
blockProperties_t blockProperties;
863864
size_t const cBlockSize = ZSTD_getcBlockSize(ip, remainingSrcSize, &blockProperties);
@@ -867,16 +868,34 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
867868
remainingSrcSize -= ZSTD_blockHeaderSize;
868869
RETURN_ERROR_IF(cBlockSize > remainingSrcSize, srcSize_wrong, "");
869870

871+
if (ip >= op && ip < oBlockEnd) {
872+
/* We are decompressing in-place. Limit the output pointer so that we
873+
* don't overwrite the block that we are currently reading. This will
874+
* fail decompression if the input & output pointers aren't spaced
875+
* far enough apart.
876+
*
877+
* This is important to set, even when the pointers are far enough
878+
* apart, because ZSTD_decompressBlock_internal() can decide to store
879+
* literals in the output buffer, after the block it is decompressing.
880+
* Since we don't want anything to overwrite our input, we have to tell
881+
* ZSTD_decompressBlock_internal to never write past ip.
882+
*
883+
* See ZSTD_allocateLiteralsBuffer() for reference.
884+
*/
885+
oBlockEnd = op + (ip - op);
886+
}
887+
870888
switch(blockProperties.blockType)
871889
{
872890
case bt_compressed:
873-
decodedSize = ZSTD_decompressBlock_internal(dctx, op, (size_t)(oend-op), ip, cBlockSize, /* frame */ 1, not_streaming);
891+
decodedSize = ZSTD_decompressBlock_internal(dctx, op, (size_t)(oBlockEnd-op), ip, cBlockSize, /* frame */ 1, not_streaming);
874892
break;
875893
case bt_raw :
894+
/* Use oend instead of oBlockEnd because this function is safe to overlap. It uses memmove. */
876895
decodedSize = ZSTD_copyRawBlock(op, (size_t)(oend-op), ip, cBlockSize);
877896
break;
878897
case bt_rle :
879-
decodedSize = ZSTD_setRleBlock(op, (size_t)(oend-op), *ip, blockProperties.origSize);
898+
decodedSize = ZSTD_setRleBlock(op, (size_t)(oBlockEnd-op), *ip, blockProperties.origSize);
880899
break;
881900
case bt_reserved :
882901
default:

0 commit comments

Comments
 (0)