summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-xref.c
AgeCommit message (Collapse)Author
2016-11-14Make fz_buffer structure private to fitz.Robin Watts
Move the definition of the structure contents into new fitz-imp.h file. Make all code outside of fitz access the buffer through the defined API. Add a convenience API for people that want to get buffers as null terminated C strings.
2016-11-14Add optional 'object' argument to pdf_add_stream.Tor Andersson
2016-11-11Add pdf_layer configuration API.Robin Watts
Add API to: * allow enumeration of layer configs (OCCDs) within PDF files. * allow selection of layer configs. * allow enumeration of the "UI" (or "Human readable") form of layer configs. * allow selection/toggling of entries in the UI.
2016-11-03Fix signed/unsigned and size_t/int/fz_off_t warnings.Robin Watts
All seen in MSVC, mostly in 64bit builds.
2016-11-01When hinted object is not found, avoid return from within fz_try().Sebastian Rasmussen
2016-10-28Clean up link destination handling.Tor Andersson
All link destinations should be URIs, and a document specific function can be called to resolve them to actual page numbers. Outlines have cached page numbers as well as string URIs.
2016-10-18Internal drop functions don't need to check for NULL.Sebastian Rasmussen
2016-10-18Avoid checking argument to fz_drop_*()/fz_free().Sebastian Rasmussen
As fz_drop_*()/fz_free() all must handle NULL.
2016-10-12Always call fz_drop_document() to drop the document.Sebastian Rasmussen
2016-10-11Free document in fz_drop_document(), not in subclassing documents.Sebastian Rasmussen
2016-10-07pdf: Remove unneccessary document argument to pdf_to_utf8 etc.Tor Andersson
2016-10-06Update Xref reading code to cope with 19 byte entries.Robin Watts
The spec says entries should be 20 bytes long. In practise we see 19 byte long ones more often than we like. This is due to the use of a single EOL char rather than 2. The PCLm files I've seen use 19 byte ones, so update the code to cope with these.
2016-09-23Fix leak in error case of pdf_add_stream.Robin Watts
2016-09-22Bug 697015: Avoid object references vanishing during repair.Robin Watts
A PDF repair can be triggered 'just in time', when we encounter a problem in the file. The idea is that this can happen without the enclosing code being aware of it. Thus the enclosing code may be holding 'borrowed' references (such as those returned by pdf_dict_get()) at the time when the repair is triggered. We are therefore at pains to ensure that the repair does not replace any objects that exist already, so that the calling code will not have these references unexpectedly invalidated. The sole exception to this is when we replace the 'Length' fields in stream dictionaries with the actual lengths. Bug 697015 shows exactly this situation causing a reference to become invalid. The solution implemented here is to add an 'orphan list' to the document, where we put these (hopefully few, small) objects. These orphans are kept around until the document is closed.
2016-09-19fz_store: Reap passes.Robin Watts
A few commits back, we introduced the fz_key_storable concept to allow us to cope with objects that were used both as values within the store and as parts of keys within the store. This commit worked, but showed up performance problems; when the store has several million PDF objects in it, bulk changes (such as dropping a display list or document) could trigger many passes across the store. We therefore introduce a mechanism to ameliorate this. These passes, now known as "reap passes", can be batched together using fz_defer_reap_start and fz_defer_reap_end. We trigger this start/end around display list dropping, and around PDF content stream processing. This should be fine, as deferral will be interrupted if we ever run our of memory during mallocing.
2016-09-16Remove unused variable.Robin Watts
2016-09-16Silence some warnings.Robin Watts
2016-09-16Tweak store handling of PDF document destroy.Robin Watts
When we destroy a PDF document, currently we bin everything from the store. Instead, drop just the objects that are specifically tied to that document. Any object tied to the document has a pdf_obj with the required document pointer in it as the key.
2016-09-01pdf: Load/open streams by indirect reference object when possible.Tor Andersson
2016-08-30Don't try to copy a NULL dictionary.Tor Andersson
2016-07-22Bug 696941: Fix use after free.Robin Watts
The file is HORRIBLY corrupt, and triggers Sophos to think it's PDF malware (which it isn't). It does however trigger a use after free, worked around here.
2016-07-13Bug 696892: PDF annotation appearance stream synthesis SEGVRobin Watts
The code would SEGV if we were trying to synthesise an appearance stream for an annotation, and the docs pdf resources table had not been initialised. We now intialise the pdf resource tables when we initialise a pdf device. This is the earliest point we know we are going to need them, and covers all cases.
2016-07-13Use fz_malloc_struct rather than fz_calloc.Robin Watts
This helps with Memento debugging, and looks neater.
2016-07-08Separate close and drop functionality for devices and writers.Tor Andersson
Closing a device or writer may throw exceptions, but much of the foreign language bindings (JNI and JS) depend on drop to never throw an exception (exceptions in finalizers are bad).
2016-07-06Start slimming pdf_page.Tor Andersson
We want to turn pdf_page into a thin wrapper around a pdf_obj, so that any updates to the underlying PDF objects will be reflected without having to reload the pdf_page.
2016-07-06Add fitz to pdf downcasting functions for pages and annotations.Tor Andersson
2016-07-06Fix garbage collection and page grafting for indirect reference chains.Tor Andersson
The mark & sweep pass of garbage collection, and resolving indirect objects when grafting objects was following the full chain of indirect references. In the unusual case where a numbered object is itself only an indirect reference to another object, this intermediate numbered object would be missed both when marking for garbage collection, and when copying objects for grafting. Add a function to resolve only one step for these two uses. The following is an example of a file that would break during garbage collection if we follow full indirect reference chains: %PDF-1.3 1 0 obj <</Type/Catalog /Foo[2 0 R 3 0 R]>> endobj 2 0 obj 4 0 R endobj 3 0 obj 5 0 R endobj 4 0 obj <</Length 1>> stream A endstream endobj 5 0 obj <</Length 1>> stream B endstream endobj
2016-07-06pdf: Drop generation number from public interfaces.Tor Andersson
The generation number is only needed for decryption, and is assumed to be zero or irrelevant for all other uses. Store the original object number and generation in the xref slot, so that we can decrypt them even when the objects have been renumbered, without needing to pass the original object number around through the stream loading APIs.
2016-07-06pdf: Increment generation number in the xref when deleting an object.Tor Andersson
2016-07-06pdf: Check ownership when adding objects to a document.Tor Andersson
2016-06-17Use 'size_t' instead of int as appropriate.Robin Watts
This silences the many warnings we get when building for x64 in windows. This does not address any of the warnings we get in thirdparty libraries - in particular harfbuzz. These look (at a quick glance) harmless though.
2016-06-14Fix typos in various parts of the code.Sebastian Rasmussen
2016-04-27Remove useless try/catch/rethrows.Tor Andersson
2016-04-27Fix 696649: remove fz_rethrow_message calls.Tor Andersson
2016-04-26Improve fz_new_documentRobin Watts
Use a macro to make fz_new_document nicer (akin to fz_malloc_struct).
2016-04-11Bug 696696: Avoid leak when cleaning with sanitize.Robin Watts
If we rewrite a page content stream, and then drop that entire page we shouldn't leak the buffer. Or to put it another way, when we change the obj for an xref entry, ditch the cached stm_buf.
2016-03-30Use fz_new_document for pdf and html docs.Robin Watts
In particular for html docs we were getting the refcount wrong, causing us to leak on closedown.
2016-03-01Rename pdf_new_ref to pdf_add_object.Tor Andersson
2016-03-01Rename pdf_close_document to pdf_drop_document.Tor Andersson
2016-02-29Rename some functions.Tor Andersson
Remove void* typecasts.
2016-02-29Add mutool create tool, and PDF font and image resource creation.Michael Vrhel
Initial framework for creating pdfs This adds a create option to mutool for us to use in working on the API for creating content as well as adding content to existing documents. mutool create: Get page sizes and add them Start the parsing of the contents.txt file which may have multiple page information. Add the pages at the proper sizes. Further work on mutool create_pdf Remove the calls that were being made to the pdf-write device. Clean up several issues with the reading of the page contents. Get the content streams for each page associated with the page->contents Temp. created a pdf_create_page_contents procedure. I will merge this with pdf_create_page as there is significant overlap. Next is to add in the font and image resources and indirect references. Include pdfcreate in build Merge pdf_create_page_contents and pdf_create_page Add support for images in pdfcreate This adds images to the pdf document using a function stolen from pdf-device (send_image). This was renamed pdf_add_image_res and added to pdf-image. Down the road, send-image will be removed. Prior to that, I need to work on making sure that multiple copies of the same image do not end up in the document. Code was also added to create the page resources to point to the proper image in the document. Next fonts will be added in a similar manner, then I will work on computing the md5 sums of image and fonts to ensure only one copy ends up in the document. Then pdf-write will be reworked to use the same code as opposed to its current list of md5 sums that are stored in a device structure. mutool pdfcreate: support for WinAnsiEncoded fonts Added support for very simple fonts (WinAnsiEncoding). Methods added in pdf-font.c. Added first_width and last_width to fz_font_s and stem_v to pdf_font_desc_s. Ran code through memento with simple test of 4 page document creation including an image and a font. Fixed several leaks as well as buffer corruption issues (main changes in pdfcreate). Thanks to Robin for the help with Memento in finding leaks. Added StemV to pdf names as it was needed for the font descriptor creation. Fix for pdf_write_document rename to pdf_save_document Add resource_ids to pdf document structure The purpose of this structure will be to allow the search and reuse of resources when we attempt to add new ones to the document. Fix name changes from recent updates pdf_create branch updated to work with recent changes in master Initial use of hash table for resources To avoid adding in the same resource this adds a resource_tables member to pdf_document. The resource_tables structure consists of multiple fz_hash_table entries, one for each resource type. When an attempt is made to search for an existing resource, the table will be initialized in a brute force search for existing resources. Currently this is only set up for the image resources and accessed through pdf_add_image_res. If a match is found, the reference object is returned. If no match is found NULL is returned and the ref object created in pdf_add_image_res is added into the hash table. In this case, a command line such as create -o output.pdf -f F0:font.ttf -i Im0:image.jpg -i Im1:image1.jpg \\ -i Im2:image.jpg contents.txt will avoid the insertion of two copies of image.jpg into the output PDF document. CID Identity-H Font added for handing ttf This adds a method for adding a ttf to a PDF as a CID font with Identity-H mapping and a ToUnicode entry that is created using FT_Get_Char_Index This takes much care in the creation of the ToUnicode CMap to ensure that the minimum number of entries are created in that we try to use beginbfrange as much as possible before using beginbfchar. The code makes sure to limit the number of entries in a group to 100 and to not cross first-byte boundaries for the CID values as described in the Adobe Technical note 5411. Add missing file pdf-resources.c pdf-resources.c was missing and should have been committed earlier. Added to windows project file. Not sure where else it needs to be added for the other platforms. Clean up names and spacing Make sure that the visible functions have the proper namespace (e.g. pdf_xxxx) Also make sure we have a blank line prior to comment. Be consistent with static function naming in pdf_resources.c pdfwrite make use of image resource fz_hash_table The pdfwrite device now shares the structure that stores the resource images for pdfcreate. With this fix, pdfwrite now avoids duplicating the writing of the same images that are shared across multiple pages. Add missing file pdf-resources.c Initial work toward having pdfwrite use Identity-H Type0 encoding for fonts Finish of CID type0 Identity-H font for pdfwrite This adds in the proper widths which may have been stored in the source font in the width table (parsed from the W entry in the pdf file) or if the free type structure has its own cmap then we can get the width from free type. Widths are restructured into format described in 5.6.3 of PDF spec. Fix issue from conflict merging and multiple define of structure Clean up warnings and make mutool create use simple font
2016-01-20Various formatting cleanups.Tor Andersson
2015-12-28Drop 'jsimp' abstraction and use mujs directly.Tor Andersson
2015-12-18Remove fz_save_document and use pdf_save_document directly instead.Tor Andersson
In preparation of adding pdf_write_document that writes a document to a fz_output stream.
2015-12-15Rename fz_write_x to fz_save_pixmap_as_x or fz_save_bitmap_as_x.Tor Andersson
Separate naming of functions that save complete files to disk from functions that write data to streams.
2015-10-21Fix signatures for files created with pdf_create_document.Simon Reinhardt
See Bug 696284. Do not set disallow_new_increments in pdf_create_document, as this breaks following calls to pdf_sign_signature. See also the comments in bug 696251.
2015-10-14Fix pdf_create_document.Simon Reinhardt
In pdf_create_document set disallow_new_increments to 1. Without this, the calls to pdf_new_ref in pdf_create_document create an incremental xref section. The following call to pdf_set_populating_xref_trailer then does not set the trailer of the final xref section.
2015-10-02Bug 696131: Detect some overflow conditionsRobin Watts
When lexing a number, do NOT check for overflow. This causes loss of data in some files. The current implementation matches Acrobat. When lexing a startxref offset, check for overflow. If found, throw an error.
2015-10-02Bug 696129: Be more forgiving of broken files.Robin Watts
The PDF spec says that old format xrefs should start with: xref\n<start> <len> The example file in question has: xref <start> <len> which confuses our parsing code. Update the parse code to avoid using fz_read_line, and to instead work on a char level. Also, downgrade the error given when the first object is not free to be a warning. Now we do 'just in time' repair, we are probably better able to cope.
2015-10-01Bug 696146: Improve pdf_repair to find /Root in new style XRefs.Robin Watts
The current code never looks for /Root objects in dictionaries as it parses them. This means that 'New style' files end up without any Roots after repair. The new code therefore updates pdf_repair_obj to look for Root objects in the same way it looks for encrypt and id objects. These go into the list of found roots. The Root object almost certainly has indirections within it, so it is vital that the 'doc' pointer gets set. This means we have to make a slight adjustment to pdf_repair_obj so that the dict is parsed with a doc pointer. In turn this means we need to manually ensure that none of the other information read from the dict during the repair operation will cause indirections to be resolved. This is achieved by checking for !pdf_is_indirect at various points.