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

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