Merge tag 'kgdb-5.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt...
[linux-2.6-microblaze.git] / lib / decompress_unzstd.c
index 0ad2c15..6b629ab 100644 (file)
@@ -16,7 +16,7 @@
  * uncompressible. Thus, we must look for worst-case expansion when the
  * compressor is encoding uncompressible data.
  *
- * The structure of the .zst file in case of a compresed kernel is as follows.
+ * The structure of the .zst file in case of a compressed kernel is as follows.
  * Maximum sizes (as bytes) of the fields are in parenthesis.
  *
  *    Frame Header: (18)
@@ -56,7 +56,7 @@
 /*
  * Preboot environments #include "path/to/decompress_unzstd.c".
  * All of the source files we depend on must be #included.
- * zstd's only source dependeny is xxhash, which has no source
+ * zstd's only source dependency is xxhash, which has no source
  * dependencies.
  *
  * When UNZSTD_PREBOOT is defined we declare __decompress(), which is
@@ -178,8 +178,13 @@ static int INIT __unzstd(unsigned char *in_buf, long in_len,
        int err;
        size_t ret;
 
+       /*
+        * ZSTD decompression code won't be happy if the buffer size is so big
+        * that its end address overflows. When the size is not provided, make
+        * it as big as possible without having the end address overflow.
+        */
        if (out_len == 0)
-               out_len = LONG_MAX; /* no limit */
+               out_len = UINTPTR_MAX - (uintptr_t)out_buf;
 
        if (fill == NULL && flush == NULL)
                /*