[LZ4_compress_destSize] Fix overflow condition
authorNick Terrell <terrelln@fb.com>
Wed, 17 Jul 2019 18:50:47 +0000 (11:50 -0700)
committerNick Terrell <terrelln@fb.com>
Wed, 17 Jul 2019 18:50:47 +0000 (11:50 -0700)
lib/lz4.c

index 461644d..74a9247 100644 (file)
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -1027,7 +1027,7 @@ _next_match:
             }
 
             if ((outputDirective) &&    /* Check output buffer overflow */
-                (unlikely(op + (1 + LASTLITERALS) + (matchCode>>8) > olimit)) ) {
+                (unlikely(op + (1 + LASTLITERALS) + (matchCode+240)/255 > olimit)) ) {
                 if (outputDirective == fillOutput) {
                     /* Match description too long : reduce it */
                     U32 newMatchCode = 15 /* in token */ - 1 /* to avoid needing a zero byte */ + ((U32)(olimit - op) - 1 - LASTLITERALS) * 255;