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

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