From 71ac78f59978197c68aa1c91c407e6bb6c581dbe Mon Sep 17 00:00:00 2001 From: Pavel Zhukov Date: Thu, 2 Mar 2017 21:41:02 +0100 Subject: [PATCH] Fix heap buffer overflow (#1425338) --- mupdf-Bug-697500-Fix-NULL-ptr-access.patch | 91 +++++++++++++++++++ ...ut-of-bounds-read-in-fz_subsample_pi.patch | 51 +++++++++++ mupdf.spec | 10 +- 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 mupdf-Bug-697500-Fix-NULL-ptr-access.patch create mode 100644 mupdf-bug-697515-Fix-out-of-bounds-read-in-fz_subsample_pi.patch diff --git a/mupdf-Bug-697500-Fix-NULL-ptr-access.patch b/mupdf-Bug-697500-Fix-NULL-ptr-access.patch new file mode 100644 index 0000000..bc1bfe1 --- /dev/null +++ b/mupdf-Bug-697500-Fix-NULL-ptr-access.patch @@ -0,0 +1,91 @@ +From 1912de5f08e90af1d9d0a9791f58ba3afdb9d465 Mon Sep 17 00:00:00 2001 +From: Robin Watts +Date: Thu, 9 Feb 2017 15:49:15 +0000 +Subject: [PATCH 2/2] Bug 697500: Fix NULL ptr access. + +Cope better with errors during rendering - avoid letting the +gstate stack get out of sync. + +This avoids us ever getting into the situation of popping +a clip when we should be popping a mask or a group. This was +causing an unexpected case in the painting. +--- + source/pdf/pdf-op-run.c | 26 ++++++++++++++++++-------- + 1 file changed, 18 insertions(+), 8 deletions(-) + +diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c +index a3ea895..f1eac8d 100644 +--- a/source/pdf/pdf-op-run.c ++++ b/source/pdf/pdf-op-run.c +@@ -1213,6 +1213,7 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf + pdf_run_processor *pr = (pdf_run_processor *)proc; + pdf_gstate *gstate = NULL; + int oldtop = 0; ++ int oldbot = -1; + fz_matrix local_transform = *transform; + softmask_save softmask = { NULL }; + int gparent_save; +@@ -1232,16 +1233,17 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf + fz_var(cleanup_state); + fz_var(gstate); + fz_var(oldtop); ++ fz_var(oldbot); + + gparent_save = pr->gparent; + pr->gparent = pr->gtop; ++ oldtop = pr->gtop; + + fz_try(ctx) + { + pdf_gsave(ctx, pr); + + gstate = pr->gstate + pr->gtop; +- oldtop = pr->gtop; + + pdf_xobject_bbox(ctx, xobj, &xobj_bbox); + pdf_xobject_matrix(ctx, xobj, &xobj_matrix); +@@ -1302,12 +1304,25 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf + + doc = pdf_get_bound_document(ctx, xobj->obj); + ++ oldbot = pr->gbot; ++ pr->gbot = pr->gtop; ++ + pdf_process_contents(ctx, (pdf_processor*)pr, doc, resources, xobj->obj, NULL); + } + fz_always(ctx) + { ++ /* Undo any gstate mismatches due to the pdf_process_contents call */ ++ if (oldbot != -1) ++ { ++ while (pr->gtop > pr->gbot) ++ { ++ pdf_grestore(ctx, pr); ++ } ++ pr->gbot = oldbot; ++ } ++ + if (cleanup_state >= 3) +- pdf_grestore(ctx, pr); /* Remove the clippath */ ++ pdf_grestore(ctx, pr); /* Remove the state we pushed for the clippath */ + + /* wrap up transparency stacks */ + if (transparency) +@@ -1341,13 +1356,8 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf + pr->gstate[pr->gparent].ctm = gparent_save_ctm; + pr->gparent = gparent_save; + +- if (gstate) +- { +- while (oldtop < pr->gtop) +- pdf_grestore(ctx, pr); +- ++ while (oldtop < pr->gtop) + pdf_grestore(ctx, pr); +- } + + pdf_unmark_obj(ctx, xobj->obj); + } +-- +2.9.3 + diff --git a/mupdf-bug-697515-Fix-out-of-bounds-read-in-fz_subsample_pi.patch b/mupdf-bug-697515-Fix-out-of-bounds-read-in-fz_subsample_pi.patch new file mode 100644 index 0000000..558be1d --- /dev/null +++ b/mupdf-bug-697515-Fix-out-of-bounds-read-in-fz_subsample_pi.patch @@ -0,0 +1,51 @@ +From 2c4e5867ee699b1081527bc6c6ea0e99a35a5c27 Mon Sep 17 00:00:00 2001 +From: Robin Watts +Date: Thu, 9 Feb 2017 07:12:16 -0800 +Subject: [PATCH 1/2] bug 697515: Fix out of bounds read in fz_subsample_pixmap + +Pointer arithmetic for final special case was going wrong. +--- + source/fitz/pixmap.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c +index a831712..f1291dc 100644 +--- a/source/fitz/pixmap.c ++++ b/source/fitz/pixmap.c +@@ -1104,6 +1104,7 @@ fz_subsample_pixmap_ARM(unsigned char *ptr, int w, int h, int f, int factor, + "@STACK:r1,<9>,factor,n,fwd,back,back2,fwd2,divX,back4,fwd4,fwd3,divY,back5,divXY\n" + "ldr r4, [r13,#4*22] @ r4 = divXY \n" + "ldr r5, [r13,#4*11] @ for (nn = n; nn > 0; n--) { \n" ++ "ldr r8, [r13,#4*17] @ r8 = back4 \n" + "18: @ \n" + "mov r14,#0 @ r14= v = 0 \n" + "sub r5, r5, r1, LSL #8 @ for (xx = x; xx > 0; x--) { \n" +@@ -1120,7 +1121,7 @@ fz_subsample_pixmap_ARM(unsigned char *ptr, int w, int h, int f, int factor, + "mul r14,r4, r14 @ r14= v *= divX \n" + "mov r14,r14,LSR #16 @ r14= v >>= 16 \n" + "strb r14,[r9], #1 @ *d++ = r14 \n" +- "sub r0, r0, r8 @ s -= back2 \n" ++ "sub r0, r0, r8 @ s -= back4 \n" + "subs r5, r5, #1 @ n-- \n" + "bgt 18b @ } \n" + "21: @ \n" +@@ -1249,6 +1250,7 @@ fz_subsample_pixmap(fz_context *ctx, fz_pixmap *tile, int factor) + x += f; + if (x > 0) + { ++ int back4 = x * n - 1; + div = x * y; + for (nn = n; nn > 0; nn--) + { +@@ -1263,7 +1265,7 @@ fz_subsample_pixmap(fz_context *ctx, fz_pixmap *tile, int factor) + s -= back5; + } + *d++ = v / div; +- s -= back2; ++ s -= back4; + } + } + } +-- +2.9.3 + diff --git a/mupdf.spec b/mupdf.spec index d5db600..36d048f 100644 --- a/mupdf.spec +++ b/mupdf.spec @@ -1,6 +1,6 @@ Name: mupdf Version: 1.10a -Release: 3%{?dist} +Release: 4%{?dist} Summary: A lightweight PDF viewer and toolkit Group: Applications/Publishing License: GPLv3 @@ -12,6 +12,9 @@ BuildRequires: openjpeg2-devel jbig2dec-devel desktop-file-utils BuildRequires: libjpeg-devel freetype-devel libXext-devel curl-devel BuildRequires: harfbuzz-devel Patch0: %{name}-1.10a-openjpeg.patch +## https://bugzilla.redhat.com/show_bug.cgi?id=1425338 +Patch1: %{name}-Bug-697500-Fix-NULL-ptr-access.patch +Patch2: %{name}-bug-697515-Fix-out-of-bounds-read-in-fz_subsample_pi.patch %description MuPDF is a lightweight PDF viewer and toolkit written in portable C. @@ -42,6 +45,8 @@ applications that use mupdf and static libraries %setup -q -n %{name}-%{version}-source rm -rf thirdparty %patch0 -p1 +%patch1 -p1 +%patch2 -p1 %build export CFLAGS="%{optflags} -fPIC -DJBIG_NO_MEMENTO -DTOFU -DTOFU_CJK" @@ -79,6 +84,9 @@ update-desktop-database &> /dev/null || : %{_libdir}/lib%{name}*.a %changelog +* Thu Mar 2 2017 Pavel Zhukov - 1.10a-4 +- fix buffer overflow (#1425338) + * Thu Mar 02 2017 Michael J Gruber - 1.10a-3 - Several packaging fixes