From: Frediano Ziglio Date: Wed, 29 Apr 2020 14:10:24 +0000 (+0100) Subject: [PATCH] quic: Check image size in quic_decode_begin X-Git-Tag: archive/raspbian/0.33-3.3+deb9u2+rpi1^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7f26796acdff20c6c92f1a437f342d05b4738bec;p=spice-gtk.git [PATCH] quic: Check image size in quic_decode_begin Avoid some overflow in code due to images too big or negative numbers. Signed-off-by: Frediano Ziglio Acked-by: Uri Lublin Gbp-Pq: Name CVE-2020-14355_part2.patch --- diff --git a/spice-common/common/quic.c b/spice-common/common/quic.c index d6fb8f2..13f84be 100644 --- a/spice-common/common/quic.c +++ b/spice-common/common/quic.c @@ -68,6 +68,9 @@ typedef uint8_t BYTE; #define MINwminext 1 #define MAXwminext 100000000 +/* Maximum image size in pixels, mainly to avoid possible integer overflows */ +#define SPICE_MAX_IMAGE_SIZE (512 * 1024 * 1024 - 1) + typedef struct QuicFamily { unsigned int nGRcodewords[MAXNUMCODES]; /* indexed by code number, contains number of unmodified GR codewords in the code */ @@ -1408,6 +1411,16 @@ int quic_decode_begin(QuicContext *quic, uint32_t *io_ptr, unsigned int num_io_w height = encoder->io_word; decode_eat32bits(encoder); + if (width <= 0 || height <= 0) { + encoder->usr->warn(encoder->usr, "invalid size\n"); + return QUIC_ERROR; + } + + /* avoid too big images */ + if ((uint64_t) width * height > SPICE_MAX_IMAGE_SIZE) { + encoder->usr->error(encoder->usr, "image too large\n"); + } + quic_image_params(encoder, type, &channels, &bpc); if (!encoder_reste_channels(encoder, channels, width, bpc)) {