Blame SOURCES/0001-Do-not-crash-when-ncbytes-is-larger-than-the-buffer-.patch

7703fd
diff --git a/libgcab/cabinet.c b/libgcab/cabinet.c
7703fd
index a675d1b..9847f1c 100644
7703fd
--- a/libgcab/cabinet.c
7703fd
+++ b/libgcab/cabinet.c
7703fd
@@ -460,18 +460,38 @@ cdata_read (cdata_t *cd, u1 res_data, gint comptype,
7703fd
     gboolean success = FALSE;
7703fd
     int ret, zret = Z_OK;
7703fd
     gint compression = comptype & GCAB_COMPRESSION_MASK;
7703fd
-    guint8 *buf = compression == GCAB_COMPRESSION_NONE ? cd->out : cd->in;
7703fd
+    gsize buf_sz;
7703fd
+    guint8 *buf = NULL;
7703fd
     CHECKSUM datacsum;
7703fd
 
7703fd
-    if (compression > GCAB_COMPRESSION_MSZIP &&
7703fd
-        compression != GCAB_COMPRESSION_LZX) {
7703fd
+    /* decompress directly into ->out for no decompression */
7703fd
+    switch (compression) {
7703fd
+    case GCAB_COMPRESSION_NONE:
7703fd
+        buf = cd->out;
7703fd
+        buf_sz = sizeof(cd->out);
7703fd
+        break;
7703fd
+    case GCAB_COMPRESSION_MSZIP:
7703fd
+    case GCAB_COMPRESSION_LZX:
7703fd
+        buf = cd->in;
7703fd
+        buf_sz = sizeof(cd->in);
7703fd
+        break;
7703fd
+    default:
7703fd
         g_set_error (error, GCAB_ERROR, GCAB_ERROR_FAILED,
7703fd
                      _("unsupported compression method %d"), compression);
7703fd
-        return FALSE;
7703fd
+        break;
7703fd
     }
7703fd
+    if (buf == NULL)
7703fd
+        return FALSE;
7703fd
 
7703fd
     R4 (cd->checksum);
7703fd
     R2 (cd->ncbytes);
7703fd
+    if (cd->ncbytes > buf_sz) {
7703fd
+        g_set_error (error, GCAB_ERROR, GCAB_ERROR_FAILED,
7703fd
+                     "tried to decompress %" G_GUINT16_FORMAT " bytes "
7703fd
+                     "into buffer of size %" G_GSIZE_FORMAT,
7703fd
+                     cd->ncbytes, buf_sz);
7703fd
+        return FALSE;
7703fd
+    }
7703fd
     R2 (cd->nubytes);
7703fd
     cd->reserved = g_malloc (res_data);
7703fd
     RN (cd->reserved, res_data);