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

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