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

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