summaryrefslogtreecommitdiff
path: root/source/pdf
AgeCommit message (Collapse)Author
2014-10-28fix memory leaks in load_sample_func and pdf_load_compressed_inline_imageSimon Bünzli
In load_sample_func, the stream is not closed and thus leaked if one of the fz_read_byte or fz_read_bits calls throws (which might happen e.g. on a Deflate data error). In pdf_load_compressed_inline_image, the allocated buffer is not freed if one of the stream initializers or the tile creation throws (fz_open_leecher does not take ownership of the stream).
2014-10-22Fix warnings.Tor Andersson
2014-09-30Fix 695501: Intelligent cmap remapping.Tor Andersson
Use the actual ranges from the cpt-to-gid cmap to optimize the remapping of ToUnicode cmaps from cpt-to-unicode into gid-to-unicode format.
2014-09-23Fix 695501: check upper and lower bounds of CMap when computing ToUnicode.Tor Andersson
When inverting the CMap to create a ToUnicode, first check the actual range of input characters rather than relying only on the codespace range list.
2014-09-17Fix whitespace.Tor Andersson
2014-09-09test-device: Abort interpretation when color found.Robin Watts
Add a new class of errors and use them to abort interpretation when the test device detects a color page.
2014-09-08Revert part of commit 5509a4ef7520bf0b5280ce7d6af8eb15b1b8b0f1Simon Bünzli
Even though the encryption key length isn't supposed to be taken from the encryption dictionary's /Length for crypt version 4, other readers such as Adobe's still use that value if a crypt filter's /Length is missing. See https://code.google.com/p/sumatrapdf/issues/detail?id=2710 for a document where this makes a difference (or simply remove /Length from the crypt filter in any document encrypted with crypt version 4 and an AESV2 crypt filter).
2014-09-02Add fz_snprintf and use it for formatting floating point numbers.Tor Andersson
2014-08-19try not to wrongly overwrite /ID when repairing encrypted documentsSimon Bünzli
If garbage is appended to an encrypted document, there could be another trailer with /ID but without /Encrypt . The repairing code currently always uses the last encountered values, but replacing the /ID value alone can cause decryption to break. One possible solution is to use the /ID value only when there's either none yet, when there's no /Encrypt or when there's a matching /Encrypt in the same trailer. See https://code.google.com/p/sumatrapdf/issues/detail?id=2697 for a document which Adobe Reader is able to read but MuPDF isn't (it used to before pdf_lex_no_string was introduced, but that's accidental).
2014-07-22Change js_is/touserdata argument order to match MuJS changes.Tor Andersson
2014-07-18allow to extract text for uncacheable glyphsSimon Bünzli
Certain glyphs such as found in nested Type 3 font can't be cached. Currently, the text extraction device doesn't see these as they're sent only as drawing operations. Sending them also as invisible text fixes potentially missing letters.
2014-07-18report more cases of blending use for pdf_pageSimon Bünzli
pdf_page::transparency is supposed to indicate whether a page uses PDF transparency features. The checks aren't complete, though, which is relevant for devices which require additional handling for transparency (such as SumatraPDF's gdiplus_device). See https://code.google.com/p/sumatrapdf/issues/detail?id=2107 and https://code.google.com/p/sumatrapdf/issues/detail?id=2540 for example documents.
2014-07-18properly decrypt strings in encrypted but broken documentsSimon Bünzli
If a PDF document is encrypted but broken, repairing caches all strings in encrypted form. Clearing the xref after repairing ensures that strings are returned to API callers as expected. Cf. https://code.google.com/p/sumatrapdf/issues/detail?id=2610
2014-07-18hex-encode UTF-16 strings when writing PDFSimon Bünzli
fmt_obj calculates whether a string is better hex-encoded or written using escapes. Due to a bug, '\0' is considered to be escapable same as '\n' when instead it would have to be written as '\000'. Since UTF-16 strings tend to consist of many '\0' bytes, their octal encoded form is much longer than their hex encoded form. The issue is that the first argument to strchr contains an unintended trailing '\0' which has to be special-cased first.
2014-07-18Bug 695271: fix incremental updates for files without final linebreakSimon Bünzli
PDF documents aren't required to end in a linebreak. Objects however must start on their own line (in particular for broken documents relying on reparation). For this reason, a linebreak must be inserted before starting an incremental update.
2014-07-17Improve callback for loading substitute CJK fonts to return TTC index.Tor Andersson
2014-06-16Fix a fatal compiler warning when building with the latest version of the ↵Matt Holgate
Android NDK (security issue because a variable is used as a format string with no parameters).
2014-06-09Bug 695300: Sanitize draw-device stack handling in error cases.Robin Watts
When throwing an error during fz_alpha_from_gray, the stack depth can get confused. Fix this by moving some more code into the appropriate fz_try(). In the course of fixing this bug, I added some new optional debug code to display the stack level as it runs. This is committed here disabled; just change the appropriate #define in draw-device.c to enable it. Also, add some code to run_xobject, to avoid throwing in an fz_always() clause.
2014-06-09Fix 695300: don't throw exception on invalid reference number.Tor Andersson
Return the null object rather than throwing an exception when parsing indirect object references with negative object numbers. Do range check for object numbers (1 .. length) when object numbers are used instead. Object number 0 is not a valid object number. It must always be 'free'.
2014-05-29Fix 694093: add vertical variant of CJK fallback font.Tor Andersson
Replace the DroidSansFallback TTF files with a TTC that has two fonts: The original and a copy where the OpenType 'vert' substitution lookup has been pre-applied by copying the uniXXXX.vert glyph data to uniXXXX.
2014-05-29fix memory leaks during PDF document creationSimon Bünzli
pdf_create_document leaks the trailer and in pdf-device.c many objects are inserted into dictionaries using pdf_dict_puts and leaked instead of using pdf_dict_puts_drop.
2014-05-29Tolerate zero-sized xref sections...Tor Andersson
...like the one Microsoft Word generates.
2014-05-27Fix 693517: Support /SMask/Matte preblended images.Tor Andersson
2014-05-27Bug 695260: Fix error handling in do_xobjectRobin Watts
Various functions (such as fz_begin_group) handle errors internally by use of the error_depth parameter. This means that if we call them, we MUST ensure that we call the appropriate closing function. Similarly, if we don't call them, we should NOT call the closing function. In order to ensure we do this correctly, we introduce a cleanup_state variable that says which ones we tried to call. This cures the original bug.
2014-05-22Flush pending text on a change of CTM.Robin Watts
Without this, comparefiles/Bug695086 renders the barcode test upside down.
2014-05-22Load the usecmap directives recursively for builtin CMaps.Tor Andersson
Fixes bug introduced in commit 1679c1e7a89ae62260fd84ce55c6bef376c6e6ba: Optimize UniXXX CMap files.
2014-05-19Make unresolvable link destinations warnings instead of errors.Tor Andersson
See bug 693314 (file Z23-04.pdf) for an example file.
2014-05-15Fix 695101 and 694114: Use the correct numbers to validate the encryption ↵Tor Andersson
key length. This reverts commit b1ed116091b790223a976eca2381da2875341e10. The key length for V==2 must be 40 <= length <= 128. The key length for V==4 is not taken from the /Length entry.
2014-05-13Use code space ranges when remapping ToUnicode CMaps.Tor Andersson
2014-05-13Fix signedness in cmap interface.Tor Andersson
2014-05-11Optimize UniXXX CMap files.Tor Andersson
Split common parts into separate CMap files and include them with usecmap. This reduces the size of the compiled in CMap resources from 3Mb to 2Mb.
2014-05-10Fix 694698: Support 32-bit values in CMaps.Tor Andersson
Increasing the existing data structure to 32-bit values would bloat the data tables too much. Simplify the data structure and use three separate range tables for lookups -- one with small 16-bit to 16-bit range lookups, one with 32-bit range lookups, and a final one for one-to-many lookups. This loses the range-to-table optimization we had before, but even with the extra ranges this necessitates, the total size of the compiled binary CMap data is smaller than if we were to extend the previous scheme to 32 bits.
2014-05-10Fix 694085: Add UTF8 and UTF32 CMaps.Tor Andersson
Remove obsolete Adobe-Japan-2 based CMaps.
2014-05-07truncate the xref after compactingSimon Bünzli
pdf_write_document still writes the entire xref with references to all freed objects even if the xref has been compacted which makes the result of mutool clean -ggg larger than necessary.
2014-05-06Fix 694909: revert "Force colorspaces to match with JPX images." and ...Tor Andersson
... instead convert a JPEG2000 used as a soft mask into grayscale. This is more robust than trusting the PDF specified colorspace over the internal JPX colorspace. The spec implies that in a colorspace conflict, the internal JPX colorspace should be used. The PDF colorspace may be a DeviceN or Separation colorspace. DeviceN and Separation colorspaces are not valid destination colorspaces, so we may not always be able to convert the internal JPX colorspace into the PDF specified colorspace. Converting from the internal colorspace into grayscale is more robust, and solves the issue that the original commit was intended to fix.
2014-05-05Fix 695098: don't use atoi() on non-zero-terminated buffer.Tor Andersson
2014-04-23Fix 693419: always load CIDToGIDMap if it exists.Tor Andersson
OpenType CFF fonts are detected as TYPE1 by ft_kind. Relaxing the test for when to load a CIDToGIDMap lets us load it even for OpenType fonts.
2014-04-23Fix 693391: simplify warning messageTor Andersson
Don't print the code point number, to let the inhibition of multiple identical warnings kick in.
2014-04-11Invalidate cached page count value when inserting and deleting pages.Tor Andersson
2014-04-11Add all form field flags. Check flags before marking fields dirty.Tor Andersson
NoExport (and ReadOnly) fields shouldn't mark the document for saving.
2014-04-01Tidy up code in pdf_load_compressed_inline_imageRobin Watts
After rushing to get the fix for a crash in, I realised the routine could be simplified a bit.
2014-03-25Bug 695089: inherit resources for softmasks (regression fix)Simon Bünzli
2014-03-25Avoid double closing a stream.Robin Watts
Michael spotted that double closing an fz_stream on an inline image does bad things. Simple fix is not to double close.
2014-03-25Break dependencies on pdf-form.c and pdf-js.cTor Andersson
Split functions out of pdf-form.c that shouldn't be there, and make javascript initialization explicit.
2014-03-25Break dependency of pdf-annot.c to graphics library.Tor Andersson
2014-03-25Add MuJS submodule, implementation and build.Tor Andersson
Adds simpler choice of Javascript library to makefiles. Will prefer in order: MuJS, JavaScriptCore, V8, none based on HAVE_MUJS, HAVE_JSCORE, and HAVE_V8. For simplicity, we build mujstest even with no javascript implementation.
2014-03-20pdf-util.js: Simplify padZeros.Tor Andersson
2014-03-20pdf-js.c: Use different random number.Tor Andersson
0.4 is not exactly representable using floats, and libjs uses a different atod function than v8.
2014-03-19Add routine to clean pdf content streams for pages.Robin Watts
New routine to filter the content streams for pages, xobjects, type3 charprocs, patterns etc. The filtered streams are guaranteed to be properly matched with q/Q's, and to not have changed the top level ctm. Additionally we remove (some) repeated settings of colors etc. This filtering can be extended to be smarter later. The idea of this is to both repair after editing, and to leave the streams in a form that can be easily appended to. This is preparatory to work on Bates numbering and Watermarking. Currently the streams produced are uncompressed.
2014-03-19Implement our own vsnprintf variant.Tor Andersson
The primary motivator for this is so that we can print floating point values and get the full accuracy out, without having to print 1.5 as 1.5000000, and without getting 23e24 etc. We only support %c, %f, %d, %o, %x and %s currently. We only support the zero padding qualifier, for integers. We do support some extensions: %C turns values >=128 into UTF-8. %M prints a fz_matrix. %R prints a fz_rect. %P prints a fz_point. We also implement a fprintf variant on top of this to allow for consistent results when using fz_output. a