From 2ddf58593cac393c062ab260e55b5670aadbec30 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Thu, 9 Jul 2020 13:59:53 +0000 Subject: [PATCH] tight2: Make sure jpeg isn't too big for buffer --- src/tight-encoder-v2.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tight-encoder-v2.c b/src/tight-encoder-v2.c index 11b9f4a..c29000b 100644 --- a/src/tight-encoder-v2.c +++ b/src/tight-encoder-v2.c @@ -312,14 +312,19 @@ static int tight_encode_tile_jpeg(struct tight_encoder_v2* self, &size, TJSAMP_422, quality, TJFLAG_FASTDCT); if (rc < 0) { log_error("Failed to encode tight JPEG box: %s\n", tjGetErrorStr()); - goto compress_failure; + goto failure; + } + + if (size > MAX_TILE_SIZE) { + log_error("Whoops, encoded JPEG was too big for the buffer\n"); + goto failure; } memcpy(tile->buffer, buffer, size); tile->size = size; rc = 0; -compress_failure: +failure: tjDestroy(handle); return rc;