From c962710c01d67f93a2a39d49db5b5a678df8070e Mon Sep 17 00:00:00 2001 From: Cyril Hrubis Date: Thu, 23 Oct 2014 10:31:19 +0200 Subject: [PATCH] JP2: Fix loader gettting stuck on no end marker. In case that the file ended up prematurely the read callback will spin in infinite loop because the read has returned zero. Change it to return -1 in this case which causes the openjpeg loader abort instead of the infinite loop. Signed-off-by: Cyril Hrubis --- libs/loaders/GP_JP2.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/loaders/GP_JP2.c b/libs/loaders/GP_JP2.c index 39b080d2..e1694ff2 100644 --- a/libs/loaders/GP_JP2.c +++ b/libs/loaders/GP_JP2.c @@ -86,7 +86,13 @@ static const char *color_space_name(OPJ_COLOR_SPACE color_space) static OPJ_SIZE_T jp2_io_read(void *buf, OPJ_SIZE_T size, void *io) { - return GP_IORead(io, buf, size); + ssize_t ret; + ret = GP_IORead(io, buf, size); + + if (ret == 0) + return -1; + + return ret; } static void fill_metadata(opj_image_t *img, GP_DataStorage *storage) -- 2.11.4.GIT