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

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