From d4ae4095cc1121b9a7a5ca9a444adaa08906e846 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 3 Apr 2015 16:30:19 +0100 Subject: Bug 694713: Avoid assert when using pdf_page_write When writing a pdf page, we pass page->contents to pdf_new_pdf_device. This object is assumed to be a dictionary (stream) that can be updated with the Length and stream contents once the page writing process has completed. When we are rewriting a pdf page however, this can go wrong; page->contents can be an array of objects. Not only this, in general it would be possible for several pages to share the same page contents (or maybe some of the elements of a page contents array). Updating one page should not update the others. We therefore update pdf_page_write to always create a new page->contents object and use that. Thanks to Michael Cadilhac for spotting the basic problem here. --- include/mupdf/pdf/output-pdf.h | 4 ++++ include/mupdf/pdf/page.h | 2 ++ 2 files changed, 6 insertions(+) (limited to 'include') diff --git a/include/mupdf/pdf/output-pdf.h b/include/mupdf/pdf/output-pdf.h index 1e783201..617d32fc 100644 --- a/include/mupdf/pdf/output-pdf.h +++ b/include/mupdf/pdf/output-pdf.h @@ -5,6 +5,10 @@ pdf_new_pdf_device: Create a pdf device. Rendering to the device creates new pdf content. WARNING: this device is work in progress. It doesn't currently support all rendering cases. + + Note that contents must be a stream (dictionary) to be updated (or + a reference to a stream). Callers should take care to ensure that it + is not an array, and that is it not shared with other objects/pages. */ fz_device *pdf_new_pdf_device(fz_context *ctx, pdf_document *doc, pdf_obj *contents, pdf_obj *resources, const fz_matrix *ctm, fz_buffer *buf); diff --git a/include/mupdf/pdf/page.h b/include/mupdf/pdf/page.h index 2a323ddb..79b7659e 100644 --- a/include/mupdf/pdf/page.h +++ b/include/mupdf/pdf/page.h @@ -17,6 +17,8 @@ pdf_obj *pdf_lookup_page_obj(fz_context *ctx, pdf_document *doc, int needle); */ pdf_page *pdf_load_page(fz_context *ctx, pdf_document *doc, int number); +void pdf_drop_page(fz_context *ctx, pdf_page *page); + fz_link *pdf_load_links(fz_context *ctx, pdf_page *page); /* -- cgit v1.2.3