summaryrefslogtreecommitdiff
path: root/print
diff options
context:
space:
mode:
authorleot <leot@pkgsrc.org>2017-12-18 15:07:14 +0000
committerleot <leot@pkgsrc.org>2017-12-18 15:07:14 +0000
commitcd270582ebabc7695aace23f9083b86be9ffb7a4 (patch)
treebbf4f33d508eb54718e9f62e55a1ab56672b0797 /print
parent9f2194932c603439d8f2235629cbf3c45c9770ac (diff)
downloadpkgsrc-cd270582ebabc7695aace23f9083b86be9ffb7a4.tar.gz
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 (limited to 'print')
-rw-r--r--print/zathura-pdf-mupdf/Makefile4
-rw-r--r--print/zathura-pdf-mupdf/distinfo11
-rw-r--r--print/zathura-pdf-mupdf/patches/patch-image.c35
-rw-r--r--print/zathura-pdf-mupdf/patches/patch-index.c62
-rw-r--r--print/zathura-pdf-mupdf/patches/patch-links.c51
-rw-r--r--print/zathura-pdf-mupdf/patches/patch-page.c75
-rw-r--r--print/zathura-pdf-mupdf/patches/patch-plugin.h25
-rw-r--r--print/zathura-pdf-mupdf/patches/patch-render.c48
-rw-r--r--print/zathura-pdf-mupdf/patches/patch-select.c25
-rw-r--r--print/zathura-pdf-mupdf/patches/patch-utils.c30
10 files changed, 269 insertions, 97 deletions
diff --git a/print/zathura-pdf-mupdf/Makefile b/print/zathura-pdf-mupdf/Makefile
index 97597f40e4c..3674a37bcfa 100644
--- a/print/zathura-pdf-mupdf/Makefile
+++ b/print/zathura-pdf-mupdf/Makefile
@@ -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 --git a/print/zathura-pdf-mupdf/distinfo b/print/zathura-pdf-mupdf/distinfo
index e762ac6ff3b..ef5add25c2f 100644
--- a/print/zathura-pdf-mupdf/distinfo
+++ b/print/zathura-pdf-mupdf/distinfo
@@ -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 --git a/print/zathura-pdf-mupdf/patches/patch-image.c b/print/zathura-pdf-mupdf/patches/patch-image.c
new file mode 100644
index 00000000000..a6021fe029c
--- /dev/null
+++ b/print/zathura-pdf-mupdf/patches/patch-image.c
@@ -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 --git a/print/zathura-pdf-mupdf/patches/patch-index.c b/print/zathura-pdf-mupdf/patches/patch-index.c
index bf49be73674..30bc789ac8c 100644
--- a/print/zathura-pdf-mupdf/patches/patch-index.c
+++ b/print/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: patch-index.c,v 1.4 2017/12/18 15:07:14 leot Exp $
-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>
+
+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/print/zathura-pdf-mupdf/patches/patch-links.c b/print/zathura-pdf-mupdf/patches/patch-links.c
deleted file mode 100644
index 721f834064f..00000000000
--- a/print/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/print/zathura-pdf-mupdf/patches/patch-page.c b/print/zathura-pdf-mupdf/patches/patch-page.c
new file mode 100644
index 00000000000..3558dcc7630
--- /dev/null
+++ b/print/zathura-pdf-mupdf/patches/patch-page.c
@@ -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 --git a/print/zathura-pdf-mupdf/patches/patch-plugin.h b/print/zathura-pdf-mupdf/patches/patch-plugin.h
new file mode 100644
index 00000000000..9f6a8b7cc1b
--- /dev/null
+++ b/print/zathura-pdf-mupdf/patches/patch-plugin.h
@@ -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>
+ #include <stdbool.h>
+ #include <zathura/plugin-api.h>
+ #include <mupdf/fitz.h>
+@@ -21,7 +23,6 @@ typedef struct mupdf_page_s
+ {
+ fz_page* page; /**< Reference to the mupdf page */
+ fz_context* ctx; /**< Context */
+- fz_stext_sheet* sheet; /**< Text sheet */
+ fz_stext_page* text; /**< Page text */
+ fz_rect bbox; /**< Bbox */
+ bool extracted_text; /**< If text has already been extracted */
diff --git a/print/zathura-pdf-mupdf/patches/patch-render.c b/print/zathura-pdf-mupdf/patches/patch-render.c
new file mode 100644
index 00000000000..771f3c29043
--- /dev/null
+++ b/print/zathura-pdf-mupdf/patches/patch-render.c
@@ -0,0 +1,48 @@
+$NetBSD: patch-render.c,v 1.5 2017/12/18 15:07:14 leot Exp $
+
+- Close device.
+
+ Every fz_drop_device() need a corresponding fz_close_device().
+
+ This fixes the:
+
+ warning: dropping unclosed device
+ warning: ... repeated <n> times ..
+
+ warnings.
+
+ Backport from upstream, commit 622b35440d708a187add31adab8bca747c11d2a8.
+
+- Updated for MuPDF 1.12.0
+
+ Backport from upstream, commit a3f703788f77b19bb986e14666fe0c47911adddc.
+
+--- render.c.orig 2017-01-11 21:21:14.000000000 +0000
++++ render.c
+@@ -31,21 +31,25 @@ pdf_page_render_to_buffer(mupdf_document
+ return ZATHURA_ERROR_UNKNOWN;
+ }
+
++ fz_close_device(mupdf_page->ctx, device);
+ fz_drop_device(mupdf_page->ctx, device);
+
+ fz_irect irect = { .x1 = page_width, .y1 = page_height };
+ fz_rect rect = { .x1 = page_width, .y1 = page_height };
+
+ fz_colorspace* colorspace = fz_device_bgr(mupdf_document->ctx);
+- fz_pixmap* pixmap = fz_new_pixmap_with_bbox_and_data(mupdf_page->ctx, colorspace, &irect, 1, image);
++ fz_separations* seps= fz_page_separations(mupdf_page->ctx, mupdf_page->page);
++ fz_pixmap* pixmap = fz_new_pixmap_with_bbox_and_data(mupdf_page->ctx, colorspace, &irect, seps, 1, image);
+ fz_clear_pixmap_with_value(mupdf_page->ctx, pixmap, 0xFF);
+
+ device = fz_new_draw_device(mupdf_page->ctx, NULL, pixmap);
+ fz_run_display_list(mupdf_page->ctx, display_list, device, &fz_identity, &rect, NULL);
++ fz_close_device(mupdf_page->ctx, device);
+ fz_drop_device(mupdf_page->ctx, device);
+
+ fz_drop_pixmap(mupdf_page->ctx, pixmap);
+ fz_drop_display_list(mupdf_page->ctx, display_list);
++ fz_drop_separations(mupdf_page->ctx, seps);
+
+ return ZATHURA_ERROR_OK;
+ }
diff --git a/print/zathura-pdf-mupdf/patches/patch-select.c b/print/zathura-pdf-mupdf/patches/patch-select.c
new file mode 100644
index 00000000000..d275a075573
--- /dev/null
+++ b/print/zathura-pdf-mupdf/patches/patch-select.c
@@ -0,0 +1,25 @@
+$NetBSD: patch-select.c,v 1.1 2017/12/18 15:07:14 leot Exp $
+
+Updated for MuPDF 1.12.0
+
+Backport from upstream, commit a3f703788f77b19bb986e14666fe0c47911adddc.
+
+--- select.c.orig 2017-01-11 21:21:14.000000000 +0000
++++ select.c
+@@ -24,9 +24,14 @@ pdf_page_get_text(zathura_page_t* page,
+ mupdf_page_extract_text(mupdf_document, mupdf_page);
+ }
+
+- fz_rect rect = { rectangle.x1, rectangle.y1, rectangle.x2, rectangle.y2 };
++ fz_point a = { rectangle.x1, rectangle.y1 };
++ fz_point b = { rectangle.x2, rectangle.y2 };
+
+- return fz_copy_selection(mupdf_page->ctx, mupdf_page->text, rect);
++#ifdef _WIN32
++ return fz_copy_selection(mupdf_page->ctx, mupdf_page->text, a, b, 1);
++#else
++ return fz_copy_selection(mupdf_page->ctx, mupdf_page->text, a, b, 0);
++#endif
+
+ error_ret:
+
diff --git a/print/zathura-pdf-mupdf/patches/patch-utils.c b/print/zathura-pdf-mupdf/patches/patch-utils.c
new file mode 100644
index 00000000000..f6309b17c22
--- /dev/null
+++ b/print/zathura-pdf-mupdf/patches/patch-utils.c
@@ -0,0 +1,30 @@
+$NetBSD: patch-utils.c,v 1.4 2017/12/18 15:07:14 leot Exp $
+
+Updated for MuPDF 1.12.0
+
+Backport from upstream, commit a3f703788f77b19bb986e14666fe0c47911adddc.
+
+--- utils.c.orig 2017-01-11 21:21:14.000000000 +0000
++++ utils.c
+@@ -7,17 +7,17 @@
+ void
+ mupdf_page_extract_text(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_page) {
+ if (mupdf_document == NULL || mupdf_document->ctx == NULL || mupdf_page == NULL ||
+- mupdf_page->sheet == NULL || mupdf_page->text == NULL) {
++ mupdf_page->text == NULL) {
+ return;
+ }
+
+ fz_device* text_device = NULL;
+
+ fz_try (mupdf_page->ctx) {
+- text_device = fz_new_stext_device(mupdf_page->ctx, mupdf_page->sheet, mupdf_page->text, NULL);
++ text_device = fz_new_stext_device(mupdf_page->ctx, mupdf_page->text, NULL);
+
+- /* Disable FZ_IGNORE_IMAGE to collect image blocks */
+- fz_disable_device_hints(mupdf_page->ctx, text_device, FZ_IGNORE_IMAGE);
++ /* Disable FZ_DONT_INTERPOLATE_IMAGES to collect image blocks */
++ fz_disable_device_hints(mupdf_page->ctx, text_device, FZ_DONT_INTERPOLATE_IMAGES);
+
+ fz_matrix ctm;
+ fz_scale(&ctm, 1.0, 1.0);