pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/print/zathura-pdf-mupdf zathura-pdf-mupdf: Backport pa...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0ec071e3daaa
branches:  trunk
changeset: 372835:0ec071e3daaa
user:      leot <leot%pkgsrc.org@localhost>
date:      Mon Dec 18 15:07:14 2017 +0000

description:
zathura-pdf-mupdf: Backport patches from upstream and adapt to MuPDF 1.2.0 API

- Backport all the relevant patches from upstream (NFCI, most of them were
  already backported but diverged a bit from upstream).
- Delete patches/patch-links.c, I can no longer reproduce the NULL pointer
  dereference with mupdf-1.2.0.
- Backport MuPDF 1.2.0 API update

With these zathura-pdf-mupdf works with mupdf-1.2.0.

Bump PKGREVISION.

diffstat:

 print/zathura-pdf-mupdf/Makefile               |   4 +-
 print/zathura-pdf-mupdf/distinfo               |  11 ++-
 print/zathura-pdf-mupdf/patches/patch-image.c  |  35 ++++++++++++
 print/zathura-pdf-mupdf/patches/patch-index.c  |  62 +++++++--------------
 print/zathura-pdf-mupdf/patches/patch-links.c  |  51 -----------------
 print/zathura-pdf-mupdf/patches/patch-page.c   |  75 ++++++++++++++++++++++++++
 print/zathura-pdf-mupdf/patches/patch-plugin.h |  25 ++++++++
 print/zathura-pdf-mupdf/patches/patch-render.c |  48 ++++++++++++++++
 print/zathura-pdf-mupdf/patches/patch-select.c |  25 ++++++++
 print/zathura-pdf-mupdf/patches/patch-utils.c  |  30 ++++++++++
 10 files changed, 269 insertions(+), 97 deletions(-)

diffs (truncated from 426 to 300 lines):

diff -r 8adc9960f0f4 -r 0ec071e3daaa print/zathura-pdf-mupdf/Makefile
--- a/print/zathura-pdf-mupdf/Makefile  Mon Dec 18 15:06:47 2017 +0000
+++ b/print/zathura-pdf-mupdf/Makefile  Mon Dec 18 15:07:14 2017 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.19 2017/11/23 17:20:10 wiz Exp $
+# $NetBSD: Makefile,v 1.20 2017/12/18 15:07:14 leot Exp $
 #
 
 DISTNAME=      zathura-pdf-mupdf-0.3.1
-PKGREVISION=   7
+PKGREVISION=   8
 CATEGORIES=    print
 MASTER_SITES=  https://pwmt.org/projects/zathura/plugins/download/
 
diff -r 8adc9960f0f4 -r 0ec071e3daaa print/zathura-pdf-mupdf/distinfo
--- a/print/zathura-pdf-mupdf/distinfo  Mon Dec 18 15:06:47 2017 +0000
+++ b/print/zathura-pdf-mupdf/distinfo  Mon Dec 18 15:07:14 2017 +0000
@@ -1,9 +1,14 @@
-$NetBSD: distinfo,v 1.6 2017/02/18 13:38:33 leot Exp $
+$NetBSD: distinfo,v 1.7 2017/12/18 15:07:14 leot Exp $
 
 SHA1 (zathura-pdf-mupdf-0.3.1.tar.gz) = ef37a181de96d6fca36db3ac818f790dcf3627ae
 RMD160 (zathura-pdf-mupdf-0.3.1.tar.gz) = 7497475ba55d2e7f96d23f378cbefeddd56089e4
 SHA512 (zathura-pdf-mupdf-0.3.1.tar.gz) = 87b5b8a750a6911be37a0195b0f4bc3304350f9d29173091b3eeece40350b10cb98b009b2722a69ae1e617b4242292f3eba17fea97d5276e485069180f2bd67d
 Size (zathura-pdf-mupdf-0.3.1.tar.gz) = 9755 bytes
 SHA1 (patch-document.c) = b4695700ffc3a85667a292af059d0af58b3150f1
-SHA1 (patch-index.c) = fbf31d17bbf979a74160db6d6838a11ce47d37f1
-SHA1 (patch-links.c) = 58581cbe1468ddf9c0e5a58e80c16586977be49b
+SHA1 (patch-image.c) = 65fee62ddeddf5329a9eeb868b39f26c9232f759
+SHA1 (patch-index.c) = 96022a5e5c6152e56cecad8f47c4893419536c83
+SHA1 (patch-page.c) = adbe5766d39befdde4aed0a937ff96312921eb2f
+SHA1 (patch-plugin.h) = 1e93cac827843be7a5caf887c5c3381ad16388f4
+SHA1 (patch-render.c) = 000477afe5286eb6e183cc87864c06f3f73ad8f2
+SHA1 (patch-select.c) = 5b6505ad998e1980a6cfa4dc0484f0707ea9799a
+SHA1 (patch-utils.c) = 870c37dfd7c359ad1e9891a75e9afc71ac3c36c7
diff -r 8adc9960f0f4 -r 0ec071e3daaa print/zathura-pdf-mupdf/patches/patch-image.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/print/zathura-pdf-mupdf/patches/patch-image.c     Mon Dec 18 15:07:14 2017 +0000
@@ -0,0 +1,35 @@
+$NetBSD: patch-image.c,v 1.4 2017/12/18 15:07:14 leot Exp $
+
+Updated for MuPDF 1.12.0
+
+Backport from upstream, commit a3f703788f77b19bb986e14666fe0c47911adddc.
+
+--- image.c.orig       2017-01-11 21:21:14.000000000 +0000
++++ image.c
+@@ -43,18 +43,16 @@ pdf_page_images_get(zathura_page_t* page
+   /* Extract images */
+   mupdf_page_extract_text(mupdf_document, mupdf_page);
+ 
+-  fz_page_block* block;
+-  for (block = mupdf_page->text->blocks; block < mupdf_page->text->blocks + mupdf_page->text->len; block++) {
+-    if (block->type == FZ_PAGE_BLOCK_IMAGE) {
+-      fz_image_block *image_block = block->u.image;
+-
++  fz_stext_block* block;
++  for (block = mupdf_page->text->first_block; block; block = block->next) {
++    if (block->type == FZ_STEXT_BLOCK_IMAGE) {
+       zathura_image_t* zathura_image = g_malloc(sizeof(zathura_image_t));
+ 
+-      zathura_image->position.x1 = image_block->bbox.x0;
+-      zathura_image->position.y1 = image_block->bbox.y0;
+-      zathura_image->position.x2 = image_block->bbox.x1;
+-      zathura_image->position.y2 = image_block->bbox.y1;
+-      zathura_image->data        = image_block->image;
++      zathura_image->position.x1 = block->bbox.x0;
++      zathura_image->position.y1 = block->bbox.y0;
++      zathura_image->position.x2 = block->bbox.x1;
++      zathura_image->position.y2 = block->bbox.y1;
++      zathura_image->data        = block->u.i.image;
+ 
+       girara_list_append(list, zathura_image);
+     }
diff -r 8adc9960f0f4 -r 0ec071e3daaa print/zathura-pdf-mupdf/patches/patch-index.c
--- a/print/zathura-pdf-mupdf/patches/patch-index.c     Mon Dec 18 15:06:47 2017 +0000
+++ b/print/zathura-pdf-mupdf/patches/patch-index.c     Mon Dec 18 15:07:14 2017 +0000
@@ -1,49 +1,29 @@
-$NetBSD: patch-index.c,v 1.3 2017/02/18 13:38:33 leot Exp $
+$NetBSD: patch-index.c,v 1.4 2017/12/18 15:07:14 leot Exp $
+
+index: handle outline entries with no URI
+
+Some PDFs (such as [1]) cause mupdf to return outline elements with a
+NULL uri element, which causes a NULL pointer dereference to happen in
+fz_is_external_link.
 
-Avoid possible NULL-pointer dereference.
+Catch this case, but still create a dummy entry in the outline.
+
+[1] http://www.st.com/resource/en/reference_manual/dm00093941.pdf
+
+Signed-off-by: Florian Larysch <fl%n621.de@localhost>
+
+Backported from upstream, commit 74deda65003386df216c7c0343c86d95c866f5e1.
 
 --- index.c.orig       2017-01-11 21:21:14.000000000 +0000
 +++ index.c
-@@ -51,24 +51,26 @@ build_index(fz_context* ctx, fz_document
+@@ -51,7 +51,9 @@ build_index(fz_context* ctx, fz_document
      zathura_link_type_t type               = ZATHURA_LINK_INVALID;
      zathura_rectangle_t rect               = { .x1 = 0, .y1 = 0, .x2 = 0, .y2 = 0 };
  
 -    if (fz_is_external_link(ctx, outline->uri) == 1) {
--      if (strstr(outline->uri, "file://") == outline->uri) {
--        type         = ZATHURA_LINK_GOTO_REMOTE;
--        target.value = outline->uri;
-+    if (outline->uri) {
-+      if (fz_is_external_link(ctx, outline->uri) == 1) {
-+        if (strstr(outline->uri, "file://") == outline->uri) {
-+          type         = ZATHURA_LINK_GOTO_REMOTE;
-+          target.value = outline->uri;
-+        } else {
-+          type         = ZATHURA_LINK_URI;
-+          target.value = outline->uri;
-+        }
-       } else {
--        type         = ZATHURA_LINK_URI;
--        target.value = outline->uri;
-+        float x = 0;
-+        float y = 0;
-+  
-+        type                    = ZATHURA_LINK_GOTO_DEST;
-+        target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
-+        target.page_number      = fz_resolve_link(ctx, document, outline->uri, &x, &y);
-+        target.left  = x;
-+        target.top   = y;
-+        target.scale = 0.0;
-       }
--    } else {
--      float x = 0;
--      float y = 0;
--
--      type                    = ZATHURA_LINK_GOTO_DEST;
--      target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
--      target.page_number      = fz_resolve_link(ctx, document, outline->uri, &x, &y);
--      target.left  = x;
--      target.top   = y;
--      target.scale = 0.0;
-     }
- 
-     index_element->link = zathura_link_new(type, rect, target);
++    if (outline->uri == NULL) {
++      type = ZATHURA_LINK_NONE;
++    } else if (fz_is_external_link(ctx, outline->uri) == 1) {
+       if (strstr(outline->uri, "file://") == outline->uri) {
+         type         = ZATHURA_LINK_GOTO_REMOTE;
+         target.value = outline->uri;
diff -r 8adc9960f0f4 -r 0ec071e3daaa print/zathura-pdf-mupdf/patches/patch-links.c
--- a/print/zathura-pdf-mupdf/patches/patch-links.c     Mon Dec 18 15:06:47 2017 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-$NetBSD: patch-links.c,v 1.3 2017/02/18 13:38:33 leot Exp $
-
-Avoid possible NULL-pointer dereference.
-
---- links.c.orig       2017-01-11 21:21:14.000000000 +0000
-+++ links.c
-@@ -43,25 +43,27 @@ pdf_page_links_get(zathura_page_t* page,
-     zathura_link_type_t type     = ZATHURA_LINK_INVALID;
-     zathura_link_target_t target = { 0 };
- 
--    if (fz_is_external_link(mupdf_document->ctx, link->uri) == 1) {
--      if (strstr(link->uri, "file://") == link->uri) {
--        type         = ZATHURA_LINK_GOTO_REMOTE;
--        target.value = link->uri;
-+    if (link->uri) {
-+      if (fz_is_external_link(mupdf_document->ctx, link->uri) == 1) {
-+        if (strstr(link->uri, "file://") == link->uri) {
-+          type         = ZATHURA_LINK_GOTO_REMOTE;
-+          target.value = link->uri;
-+        } else {
-+          type         = ZATHURA_LINK_URI;
-+          target.value = link->uri;
-+        }
-       } else {
--        type         = ZATHURA_LINK_URI;
--        target.value = link->uri;
-+        float x = 0;
-+        float y = 0;
-+  
-+        type                    = ZATHURA_LINK_GOTO_DEST;
-+        target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
-+        target.page_number      = fz_resolve_link(mupdf_document->ctx,
-+            mupdf_document->document, link->uri, &x, &y);
-+        target.left  = x;
-+        target.top   = y;
-+        target.scale = 0.0;
-       }
--    } else {
--      float x = 0;
--      float y = 0;
--
--      type                    = ZATHURA_LINK_GOTO_DEST;
--      target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
--      target.page_number      = fz_resolve_link(mupdf_document->ctx,
--          mupdf_document->document, link->uri, &x, &y);
--      target.left  = x;
--      target.top   = y;
--      target.scale = 0.0;
-     }
- 
-     zathura_link_t* zathura_link = zathura_link_new(type, position, target);
diff -r 8adc9960f0f4 -r 0ec071e3daaa print/zathura-pdf-mupdf/patches/patch-page.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/print/zathura-pdf-mupdf/patches/patch-page.c      Mon Dec 18 15:07:14 2017 +0000
@@ -0,0 +1,75 @@
+$NetBSD: patch-page.c,v 1.4 2017/12/18 15:07:14 leot Exp $
+
+- Fix double free in pdf_page_init()
+  
+  In case of failure in 'pdf_page_init', the mupdf_page is being cleared
+  and freed but the zathura_page still holds a pointer to it, resulting
+  in a double free when 'pdf_page_clear' is later called.
+  
+  The execution flow resulting in a double free is the following:
+    zathura_page_new()
+      pdf_page_init()
+        zathura_page_set_data()
+        failure of fz_load_page(),fz_bound_page() or fz_new_stext_sheet()
+        pdf_page_clear()
+      zathura_page_free()
+        pdf_page_clear() // double free
+  
+  Make sure 'zathura_page_set_data' is called only if no errors occurred
+  so that page->data never points to freed memory.
+  
+  Backported from upstream, commit 83b3f9e77bb6aedfa6b4fffc1088c25ae209fd81.
+
+- Updated for MuPDF 1.12.0
+  
+  Backport from upstream, commit a3f703788f77b19bb986e14666fe0c47911adddc.
+
+--- page.c.orig        2017-12-18 10:17:58.832972588 +0000
++++ page.c
+@@ -20,8 +20,6 @@ pdf_page_init(zathura_page_t* page)
+     return  ZATHURA_ERROR_OUT_OF_MEMORY;
+   }
+ 
+-  zathura_page_set_data(page, mupdf_page);
+-
+   mupdf_page->ctx = mupdf_document->ctx;
+   if (mupdf_page->ctx == NULL) {
+     goto error_free;
+@@ -36,10 +34,6 @@ pdf_page_init(zathura_page_t* page)
+ 
+   fz_bound_page(mupdf_document->ctx, (fz_page*) mupdf_page->page, &mupdf_page->bbox);
+ 
+-  /* get page dimensions */
+-  zathura_page_set_width(page,  mupdf_page->bbox.x1 - mupdf_page->bbox.x0);
+-  zathura_page_set_height(page, mupdf_page->bbox.y1 - mupdf_page->bbox.y0);
+-
+   /* setup text */
+   mupdf_page->extracted_text = false;
+ 
+@@ -50,10 +44,11 @@ pdf_page_init(zathura_page_t* page)
+     goto error_free;
+   }
+ 
+-  mupdf_page->sheet = fz_new_stext_sheet(mupdf_page->ctx);
+-  if (mupdf_page->sheet == NULL) {
+-    goto error_free;
+-  }
++  zathura_page_set_data(page, mupdf_page);
++
++  /* get page dimensions */
++  zathura_page_set_width(page,  mupdf_page->bbox.x1 - mupdf_page->bbox.x0);
++  zathura_page_set_height(page, mupdf_page->bbox.y1 - mupdf_page->bbox.y0);
+ 
+   return ZATHURA_ERROR_OK;
+ 
+@@ -79,10 +74,6 @@ pdf_page_clear(zathura_page_t* page, mup
+       fz_drop_stext_page(mupdf_page->ctx, mupdf_page->text);
+     }
+ 
+-    if (mupdf_page->sheet != NULL) {
+-      fz_drop_stext_sheet(mupdf_page->ctx, mupdf_page->sheet);
+-    }
+-
+     if (mupdf_page->page != NULL) {
+       fz_drop_page(mupdf_document->ctx, mupdf_page->page);
+     }
diff -r 8adc9960f0f4 -r 0ec071e3daaa print/zathura-pdf-mupdf/patches/patch-plugin.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/print/zathura-pdf-mupdf/patches/patch-plugin.h    Mon Dec 18 15:07:14 2017 +0000
@@ -0,0 +1,25 @@
+$NetBSD: patch-plugin.h,v 1.4 2017/12/18 15:07:14 leot Exp $
+
+Updated for MuPDF 1.12.0
+
+Backport from upstream, commit a3f703788f77b19bb986e14666fe0c47911adddc.
+
+--- plugin.h.orig      2017-01-11 21:21:14.000000000 +0000
++++ plugin.h
+@@ -3,6 +3,8 @@
+ #ifndef PDF_H
+ #define PDF_H
+ 
++#include <stdlib.h>
++#include <string.h>



Home | Main Index | Thread Index | Old Index