]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
add requested check for legacy decoder v0.1
authorYann Collet <yann.collet.73@gmail.com>
Tue, 7 Feb 2023 22:47:16 +0000 (14:47 -0800)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 7 Feb 2023 22:47:16 +0000 (14:47 -0800)
which uses a different technique to store literals,
and therefore must check for potential overwrites.

lib/legacy/zstd_v01.c

index 7f24cf685ff1b4ae15f94f1be8812dfdf65d7090..1a3aad07ed84016d97d452f852c1e62908cc58ef 100644 (file)
@@ -1735,6 +1735,7 @@ static size_t ZSTD_execSequence(BYTE* op,
 
     if (endMatch > oend) return ERROR(dstSize_tooSmall);   /* overwrite beyond dst buffer */
     if (litEnd > litLimit) return ERROR(corruption_detected);   /* overRead beyond lit buffer */
+    if (sequence.matchLength > (size_t)(*litPtr-op)) return ERROR(dstSize_tooSmall);  /* overwrite literal segment */
 
     /* copy Literals */
     ZSTD_memmove(op, *litPtr, sequence.litLength);   /* note : v0.1 seems to allow scenarios where output or input are close to end of buffer */