Blame SOURCES/0002-quic-Check-image-size-in-quic_decode_begin.patch

199a67
From 19cd6fe85610b424349db2d97e2dd0e2761a4a05 Mon Sep 17 00:00:00 2001
199a67
From: Frediano Ziglio <freddy77@gmail.com>
199a67
Date: Wed, 29 Apr 2020 15:10:24 +0100
199a67
Subject: [PATCH spice-common 2/4] quic: Check image size in quic_decode_begin
199a67
199a67
Avoid some overflow in code due to images too big or
199a67
negative numbers.
199a67
199a67
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
199a67
Acked-by: Uri Lublin <uril@redhat.com>
199a67
---
199a67
 common/quic.c | 13 +++++++++++++
199a67
 1 file changed, 13 insertions(+)
199a67
199a67
diff --git a/subprojects/spice-common/common/quic.c b/subprojects/spice-common/common/quic.c
199a67
index e03f3af..890f128 100644
199a67
--- a/subprojects/spice-common/common/quic.c
199a67
+++ b/subprojects/spice-common/common/quic.c
199a67
@@ -56,6 +56,9 @@ typedef uint8_t BYTE;
199a67
 #define MINwminext 1
199a67
 #define MAXwminext 100000000
199a67
 
199a67
+/* Maximum image size in pixels, mainly to avoid possible integer overflows */
199a67
+#define SPICE_MAX_IMAGE_SIZE (512 * 1024 * 1024 - 1)
199a67
+
199a67
 typedef struct QuicFamily {
199a67
     unsigned int nGRcodewords[MAXNUMCODES];      /* indexed by code number, contains number of
199a67
                                                     unmodified GR codewords in the code */
199a67
@@ -1165,6 +1168,16 @@ int quic_decode_begin(QuicContext *quic, uint32_t *io_ptr, unsigned int num_io_w
199a67
     height = encoder->io_word;
199a67
     decode_eat32bits(encoder);
199a67
 
199a67
+    if (width <= 0 || height <= 0) {
199a67
+        encoder->usr->warn(encoder->usr, "invalid size\n");
199a67
+        return QUIC_ERROR;
199a67
+    }
199a67
+
199a67
+    /* avoid too big images */
199a67
+    if ((uint64_t) width * height > SPICE_MAX_IMAGE_SIZE) {
199a67
+        encoder->usr->error(encoder->usr, "image too large\n");
199a67
+    }
199a67
+
199a67
     quic_image_params(encoder, type, &channels, &bpc;;
199a67
 
199a67
     if (!encoder_reset_channels(encoder, channels, width, bpc)) {
199a67
-- 
199a67
2.25.4
199a67