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

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