]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Make grub_zlib_decompress handle incomplete chunks.
authorVladimir Serbinenko <phcoder@gmail.com>
Wed, 18 Dec 2013 22:39:49 +0000 (23:39 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Wed, 18 Dec 2013 22:39:49 +0000 (23:39 +0100)
Fixes squash4.

ChangeLog
grub-core/fs/btrfs.c
grub-core/fs/hfspluscomp.c
grub-core/fs/zfs/zfs.c
grub-core/io/gzio.c

index 17d0e243e6c7b379aeddd65a0d28456688aa8a7c..8dfaf47d43bfd721b6c0b359b0720126bd6e9d41 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-12-18  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Make grub_zlib_decompress handle incomplete chunks.
+
+       Fixes squash4.
+
 2013-12-18  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/Makefile.am: Don't attempt to export grub_bios_interrupt
index b15a9d65d842484094dd0eaa99405d0e2c220f0d..89666b6fd593b417ca1e6d0c76c6ac7c4b0dbd11 100644 (file)
@@ -1104,7 +1104,12 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
                                         - (grub_uint8_t *) data->extent),
                                        extoff, buf, csize)
                  != (grub_ssize_t) csize)
-               return -1;
+               {
+                 if (!grub_errno)
+                   grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
+                               "premature end of compressed");
+                 return -1;
+               }
            }
          else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_LZO)
            {
@@ -1158,7 +1163,12 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
              grub_free (tmp);
 
              if (ret != (grub_ssize_t) csize)
-               return -1;
+               {
+                 if (!grub_errno)
+                   grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
+                               "premature end of compressed");
+                 return -1;
+               }
 
              break;
            }
index 461b4678fe4d6db0aff7446d671786d4644c0a36..d76f3f137a92515263c6f60e70aea1952ed9afe1 100644 (file)
@@ -156,8 +156,12 @@ hfsplus_read_compressed_real (struct grub_hfsplus_file *node,
          if (ts > node->size - (pos & ~(HFSPLUS_COMPRESS_BLOCK_SIZE)))
            ts = node->size - (pos & ~(HFSPLUS_COMPRESS_BLOCK_SIZE));
          if (grub_zlib_decompress (tmp_buf, sz, 0,
-                                   node->cbuf, ts) < 0)
+                                   node->cbuf, ts) != (grub_ssize_t) ts)
            {
+             if (!grub_errno)
+               grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
+                           "premature end of compressed");
+
              grub_free (tmp_buf);
              return -1;
            }
@@ -288,8 +292,14 @@ hfsplus_open_compressed_real (struct grub_hfsplus_file *node)
   if (grub_zlib_decompress ((char *) (cmp_head + 1),
                            grub_cpu_to_be64 (attr_head->size)
                            - sizeof (*cmp_head), 0,
-                           node->cbuf, node->size) < 0)
-    return grub_errno;
+                           node->cbuf, node->size)
+      != (grub_ssize_t) node->size)
+    {
+      if (!grub_errno)
+       grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
+                   "premature end of compressed");
+      return grub_errno;
+    }
   node->compressed = 1;
   return 0;
 }
index 4d0bde4ce04391ac263a69d150dc243b4149ca69..cfb25c030de2b1097345219aa13fcca52b72c237 100644 (file)
@@ -293,9 +293,13 @@ static grub_err_t
 zlib_decompress (void *s, void *d,
                 grub_size_t slen, grub_size_t dlen)
 {
-  if (grub_zlib_decompress (s, slen, 0, d, dlen) < 0)
-    return grub_errno;
-  return GRUB_ERR_NONE;
+  if (grub_zlib_decompress (s, slen, 0, d, dlen) == (grub_ssize_t) dlen)
+    return GRUB_ERR_NONE;
+
+  if (!grub_errno)
+    grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
+               "premature end of compressed");
+  return grub_errno;
 }
 
 static grub_err_t 
index aec798f5951c62ffe4cff30f81dc48f4a0db8259..129209e37d0d8e751e3cd813c6b789aab5263503 100644 (file)
@@ -1303,12 +1303,6 @@ grub_zlib_decompress (char *inbuf, grub_size_t insize, grub_off_t off,
   ret = grub_gzio_read_real (gzio, off, outbuf, outsize);
   grub_free (gzio);
 
-  if (!grub_errno && ret != (grub_ssize_t) outsize)
-    {
-      grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "premature end of compressed");
-      ret = -1;
-    }
-
   /* FIXME: Check Adler.  */
   return ret;
 }