pkgsrc-WIP-changes archive

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

zathura-pdf-mupdf: Backport a3f70378 and update TODO



Module Name:	pkgsrc-wip
Committed By:	Leonardo Taccari <leot%NetBSD.org@localhost>
Pushed By:	leot
Date:		Mon Dec 18 11:25:44 2017 +0100
Changeset:	134585f29316f70378c5e8af93cdc2d26f07845b

Modified Files:
	zathura-pdf-mupdf/TODO
	zathura-pdf-mupdf/distinfo
	zathura-pdf-mupdf/patches/patch-page.c
Added Files:
	zathura-pdf-mupdf/patches/patch-image.c
	zathura-pdf-mupdf/patches/patch-plugin.h
	zathura-pdf-mupdf/patches/patch-render.c
	zathura-pdf-mupdf/patches/patch-select.c
	zathura-pdf-mupdf/patches/patch-utils.c

Log Message:
zathura-pdf-mupdf: Backport a3f70378 and update TODO

Apparently, the problems exposed by my WIP update to MuPDF 1.12.0 are also
exposed by upstream patches... This need further investigation!

(Probably it's better to figure out what unclosed device is dropped and then,
eventually (if still there!), the SIGSEGV.)

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

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

diffstat:
 zathura-pdf-mupdf/TODO                   | 30 ++++++++++++++--
 zathura-pdf-mupdf/distinfo               |  9 +++--
 zathura-pdf-mupdf/patches/patch-image.c  | 35 ++++++++++++++++++
 zathura-pdf-mupdf/patches/patch-page.c   | 62 ++++++++++++++++++++------------
 zathura-pdf-mupdf/patches/patch-plugin.h | 25 +++++++++++++
 zathura-pdf-mupdf/patches/patch-render.c | 26 ++++++++++++++
 zathura-pdf-mupdf/patches/patch-select.c | 25 +++++++++++++
 zathura-pdf-mupdf/patches/patch-utils.c  | 30 ++++++++++++++++
 8 files changed, 216 insertions(+), 26 deletions(-)

diffs:
diff --git a/zathura-pdf-mupdf/TODO b/zathura-pdf-mupdf/TODO
index 7fb2a6bb92..225d4021fa 100644
--- a/zathura-pdf-mupdf/TODO
+++ b/zathura-pdf-mupdf/TODO
@@ -1,2 +1,28 @@
-- Backport commit a3f70378 by Pavel Vinogradov to adjust zathura-pdf-mupdf
-  for the MuPDF 1.12.0
+- With commit a3f70378, backported for the MuPDF 1.12.0 update, there are:
+
+    warning: dropping unclosed device
+    warning: ... repeated <n> times ...
+
+  ...and then when zathura is closed it crashes with a SIGSEGV.
+  The `bt' - on NetBSD/amd64, 8.99.8 with pkgsrc-current packages - is the following:
+
+ #0  0x00007c0085608d80 in ?? ()
+ #1  0x00007c0084a02645 in ?? () from /usr/lib/libgcc_s.so.1
+ #2  0x00007c0084a10610 in ?? () from /usr/lib/libgcc_s.so.1
+ #3  0x00007c0084a10619 in _fini () from /usr/lib/libgcc_s.so.1
+ #4  0x00007c0084a10610 in ?? () from /usr/lib/libgcc_s.so.1
+ #5  0x00007f7e7ec01d09 in _rtld_call_function_void (obj=<optimized out>, addr=136341669097504) at /usr/src/libexec/ld.elf_so/rtld.h:504
+ #6  _rtld_call_initfini_function (obj=<optimized out>, mask=0x7f7fff4c5830, func=136341669097504)
+     at /usr/src/libexec/ld.elf_so/rtld.c:142
+ #7  _rtld_call_fini_function (obj=<optimized out>, mask=mask@entry=0x7f7fff4c5830, cur_objgen=10)
+     at /usr/src/libexec/ld.elf_so/rtld.c:157
+ #8  0x00007f7e7ec01dc9 in _rtld_call_fini_functions (mask=mask@entry=0x7f7fff4c5830, force=force@entry=1)
+     at /usr/src/libexec/ld.elf_so/rtld.c:203
+ #9  0x00007f7e7ec0206a in _rtld_exit () at /usr/src/libexec/ld.elf_so/rtld.c:412
+ #10 0x00007c0096100422 in __cxa_finalize (dso=dso@entry=0x0) at /usr/src/lib/libc/stdlib/atexit.c:222
+ #11 0x00007c00960fffc3 in exit (status=0) at /usr/src/lib/libc/stdlib/exit.c:60
+ #12 0x000000000040eca5 in _start ()
+
+  Investigate and fix these problems if possible. 
+
+    -- leot (2017/12/18)
diff --git a/zathura-pdf-mupdf/distinfo b/zathura-pdf-mupdf/distinfo
index e762ac6ff3..02e2d1a1c5 100644
--- a/zathura-pdf-mupdf/distinfo
+++ b/zathura-pdf-mupdf/distinfo
@@ -5,5 +5,10 @@ RMD160 (zathura-pdf-mupdf-0.3.1.tar.gz) = 7497475ba55d2e7f96d23f378cbefeddd56089
 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) = 81f4bca39e5988b09a27e336ea4377cea0283305
+SHA1 (patch-select.c) = 5b6505ad998e1980a6cfa4dc0484f0707ea9799a
+SHA1 (patch-utils.c) = 870c37dfd7c359ad1e9891a75e9afc71ac3c36c7
diff --git a/zathura-pdf-mupdf/patches/patch-image.c b/zathura-pdf-mupdf/patches/patch-image.c
new file mode 100644
index 0000000000..39cb6cc5d8
--- /dev/null
+++ b/zathura-pdf-mupdf/patches/patch-image.c
@@ -0,0 +1,35 @@
+$NetBSD$
+
+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/zathura-pdf-mupdf/patches/patch-page.c b/zathura-pdf-mupdf/patches/patch-page.c
index cf1784ffe7..2c8e53ec78 100644
--- a/zathura-pdf-mupdf/patches/patch-page.c
+++ b/zathura-pdf-mupdf/patches/patch-page.c
@@ -1,26 +1,30 @@
 $NetBSD$
 
-Fix double free in pdf_page_init()
+- 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.
 
-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.
+- Updated for MuPDF 1.12.0
+  
+  Backport from upstream, commit a3f703788f77b19bb986e14666fe0c47911adddc.
 
-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.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;
@@ -42,16 +46,30 @@ Backported from upstream, commit 83b3f9e77bb6aedfa6b4fffc1088c25ae209fd81.
    /* setup text */
    mupdf_page->extracted_text = false;
  
-@@ -55,6 +49,12 @@ pdf_page_init(zathura_page_t* page)
+@@ -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;
  
- error_free:
+@@ -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/zathura-pdf-mupdf/patches/patch-plugin.h b/zathura-pdf-mupdf/patches/patch-plugin.h
new file mode 100644
index 0000000000..dc687c3cc5
--- /dev/null
+++ b/zathura-pdf-mupdf/patches/patch-plugin.h
@@ -0,0 +1,25 @@
+$NetBSD$
+
+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/zathura-pdf-mupdf/patches/patch-render.c b/zathura-pdf-mupdf/patches/patch-render.c
new file mode 100644
index 0000000000..18b8b435c2
--- /dev/null
+++ b/zathura-pdf-mupdf/patches/patch-render.c
@@ -0,0 +1,26 @@
+$NetBSD$
+
+Updated for MuPDF 1.12.0
+
+Backport from upstream, commit a3f703788f77b19bb986e14666fe0c47911adddc.
+
+--- render.c.orig	2017-01-11 21:21:14.000000000 +0000
++++ render.c
+@@ -37,7 +37,8 @@ pdf_page_render_to_buffer(mupdf_document
+   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);
+@@ -46,6 +47,7 @@ pdf_page_render_to_buffer(mupdf_document
+ 
+   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/zathura-pdf-mupdf/patches/patch-select.c b/zathura-pdf-mupdf/patches/patch-select.c
new file mode 100644
index 0000000000..6ee5f28bd8
--- /dev/null
+++ b/zathura-pdf-mupdf/patches/patch-select.c
@@ -0,0 +1,25 @@
+$NetBSD$
+
+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/zathura-pdf-mupdf/patches/patch-utils.c b/zathura-pdf-mupdf/patches/patch-utils.c
new file mode 100644
index 0000000000..89689091a7
--- /dev/null
+++ b/zathura-pdf-mupdf/patches/patch-utils.c
@@ -0,0 +1,30 @@
+$NetBSD$
+
+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);


Home | Main Index | Thread Index | Old Index