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

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