From 11c3e6e574f74981459a6401b7d8cd4773f67cc4 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 7 Nov 2018 16:58:56 +0100 Subject: Make compression bomb detection optional. --- source/cbz/muimg.c | 2 +- source/fitz/stream-read.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/source/cbz/muimg.c b/source/cbz/muimg.c index fb075307..c03c237d 100644 --- a/source/cbz/muimg.c +++ b/source/cbz/muimg.c @@ -150,7 +150,7 @@ img_open_document_with_stream(fz_context *ctx, fz_stream *file) size_t len; unsigned char *data; - doc->buffer = fz_read_all(ctx, file, 1024); + doc->buffer = fz_read_all(ctx, file, 0); len = fz_buffer_storage(ctx, doc->buffer, &data); fmt = FZ_IMAGE_UNKNOWN; diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c index 1a2bda01..9eff8722 100644 --- a/source/fitz/stream-read.c +++ b/source/fitz/stream-read.c @@ -59,6 +59,7 @@ fz_buffer * fz_read_best(fz_context *ctx, fz_stream *stm, size_t initial, int *truncated) { fz_buffer *buf = NULL; + int check_bomb = (initial > 0); size_t n; fz_var(buf); @@ -78,10 +79,8 @@ fz_read_best(fz_context *ctx, fz_stream *stm, size_t initial, int *truncated) if (buf->len == buf->cap) fz_grow_buffer(ctx, buf); - if (buf->len >= MIN_BOMB && buf->len / 200 > initial) - { + if (check_bomb && buf->len >= MIN_BOMB && buf->len / 200 > initial) fz_throw(ctx, FZ_ERROR_GENERIC, "compression bomb detected"); - } n = fz_read(ctx, stm, buf->data + buf->len, buf->cap - buf->len); if (n == 0) -- cgit v1.2.3