pkgsrc-WIP-changes archive

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

zathura-pdf-mupdf: Backport all important pre-MuPDF 1.12.0 commits from upstream



Module Name:	pkgsrc-wip
Committed By:	Leonardo Taccari <leot%NetBSD.org@localhost>
Pushed By:	leot
Date:		Mon Dec 18 10:55:04 2017 +0100
Changeset:	7684f1046849738e2eb4a96eb36cc275ba358c19

Modified Files:
	zathura-pdf-mupdf/patches/patch-index.c
Added Files:
	zathura-pdf-mupdf/patches/patch-page.c
Removed Files:
	zathura-pdf-mupdf/patches/patch-links.c

Log Message:
zathura-pdf-mupdf: Backport all important pre-MuPDF 1.12.0 commits from upstream

XXX: At the moment also remove our patch-links.c, it's probably still needed though!

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=7684f1046849738e2eb4a96eb36cc275ba358c19

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 zathura-pdf-mupdf/patches/patch-index.c | 62 +++++++++++----------------------
 zathura-pdf-mupdf/patches/patch-links.c | 51 ---------------------------
 zathura-pdf-mupdf/patches/patch-page.c  | 57 ++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 92 deletions(-)

diffs:
diff --git a/zathura-pdf-mupdf/patches/patch-index.c b/zathura-pdf-mupdf/patches/patch-index.c
index bf49be7367..8e4e20d4aa 100644
--- a/zathura-pdf-mupdf/patches/patch-index.c
+++ b/zathura-pdf-mupdf/patches/patch-index.c
@@ -1,49 +1,29 @@
-$NetBSD: patch-index.c,v 1.3 2017/02/18 13:38:33 leot Exp $
+$NetBSD$
 
-Avoid possible NULL-pointer dereference.
+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.
+
+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 --git a/zathura-pdf-mupdf/patches/patch-links.c b/zathura-pdf-mupdf/patches/patch-links.c
deleted file mode 100644
index 721f834064..0000000000
--- a/zathura-pdf-mupdf/patches/patch-links.c
+++ /dev/null
@@ -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 --git a/zathura-pdf-mupdf/patches/patch-page.c b/zathura-pdf-mupdf/patches/patch-page.c
new file mode 100644
index 0000000000..cf1784ffe7
--- /dev/null
+++ b/zathura-pdf-mupdf/patches/patch-page.c
@@ -0,0 +1,57 @@
+$NetBSD$
+
+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.
+
+--- page.c.orig	2017-01-11 21:21:14.000000000 +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;
+ 
+@@ -55,6 +49,12 @@ pdf_page_init(zathura_page_t* page)
+     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;
+ 
+ error_free:


Home | Main Index | Thread Index | Old Index