summaryrefslogtreecommitdiff
path: root/source
AgeCommit message (Collapse)Author
2014-01-10Bug 694885: Avoid stack overflow in ps_run.Robin Watts
The ifelse and if operators require special parsing where we convert ps function streams to bytecode. If a malformed stream presents if or ifelse without being preceded by the appropriate { ...} blocks then throw an error. This avoids us potentially calling ps_run recursively in an infinite loop as happens with the test file in this bug. 5f091df77f6600d0927dc36777db2b93_signal_sigabrt_7ffff6d59425_6762_5545.pdf Thanks to Mateusz Jurczyk and Gynvael Coldwind of the Google Security Team for providing the fuzzing files.
2014-01-10Bug 694879: Fix SEGV in draw-simple-scale.Robin Watts
Problems caused by the fact that -0x8000000 = 0x80000000. Sidestep the problem for all coords where floats cannot accurately represent them.
2014-01-10Fix build_filter_chain not to leak if pdf_array_get fails.Robin Watts
In the existing code, if build_filter fails, chain will be freed. If pdf_array_get fails however, it will leak. Rectify this. No specific bug or example file, just observation arising from discussions about previous commit.
2014-01-09prevent two further heap access violationsSimon Bünzli
pdf_open_raw_renumbered_stream and pdf_open_image_stream both have the same issue that 98a111c8e49916f8f5ac21d11f4627540f9ddd49 fixes.
2014-01-09Bug 694878: Fix SEGV due to double freeRobin Watts
When constructing a filter chain, we pass ownership of 'chain' inwards. This means we need to be careful not to double close chain. This fixes: 5df97f8539d31745f1c45cc9e1468825_asan_heap-oob_a59afe_1862_225.pdf a736faf6f4a34b7ad8eff207ba52aa57_asan_heap-oob_a59dd9_5744_4860.pdf Thanks to Mateusz Jurczyk and Gynvael Coldwind of the Google Security Team for providing the fuzzing files.
2014-01-09Add -o option for mutool show.Tor Andersson
Windows doesn't like redirecting binary output, so add an explicit filename argument.
2014-01-08fuzzing fix for null colorspace derefence.Robin Watts
Bad annotation appearance streams can cause font_recs to have invalid values in. Avoid this partly by hardening the code against duff values, and partly by setting sane defaults before the parsing. This can be seen in: 33bfbe117bfef7fafc3f927acf50a2e7_signal_sigsegv_81dd96_6257_5205.pdf Thanks to Mateusz Jurczyk and Gynvael Coldwind of the Google Security Team for providing the example files.
2014-01-08Fix fuzzing bug due to float representation limitations.Robin Watts
The gel bbox was being stored internally as floats (despite only holding ints). This means that as numbers get large the bbox can become approximate, rather than exact. If the bbox becomes smaller than it should, this causes crashes in the scanline filling code. This is seen with: tests_private/fuzzing/mupdf2/17f8aee51ac776994af0b36195cdadd7_signal_sigsegv_5607be_7308_5912.pdf The solution is simply to use ints rather than floats. Thanks to Mateusz Jurczyk and Gynvael Coldwind of the Google Security Team for providing the example files.
2014-01-08Fuzzing fix: Overrun in fz_predict_pngRobin Watts
If a file specifies a silly number of bpp in the PNG predictor it can overrun a buffer. This was shown by: tests_private/fuzzing/mupdf2/013b2dcbd0207501e922910ac335eb59_*.pdf but no longer shows up due to Simons earlier fix. Following discussion we still think it's worth having this fix in, as truncated data streams can cause len < bpp. Possibly we should throw an error here, but I think that's not necessary as we will return the short length, and the image reading code will notice that the image is truncated already. Thanks to Mateusz Jurczyk and Gynvael Coldwind of the Google Security Team for providing the fuzzing files.
2014-01-08prevent heap access violation in pdf_cache_objectSimon Bünzli
pdf_load_obj_stm may resize the xref if it finds further objects in the stream, that might however invalidate any pdf_xref_entry hold such as the one in pdf_cache_object. This can be seen e.g. with 7ac3ad9ddad98d10b947a43cf640062f_asan_heap-uaf_930b78_1007_1675.pdf Thanks to Mateusz Jurczyk and Gynvael Coldwind of the Google Security Team for providing the example files.
2014-01-08sanitize crypt revision in pdf_new_cryptSimon Bünzli
(Second part of Simons patch - apologies for missing this the first time). This correctly enables the sanitization of the key length needed for 90db34f64037e2a8a5c3b6a518ba4153_asan_heap-oob_9b117e_1197_1802.pdf Thanks to Mateusz Jurczyk and Gynvael Coldwind of the Google Security Team for providing the example files.
2014-01-08sanitize number of columns in fz_open_faxdSimon Bünzli
If columns is quite close to INT_MAX, the column index max overflow in find_changing which causes an access violation in the next getbits. This happens e.g. with 0c76a20163f30ea8ec860c4e588ce337_signal_sigsegv_5e7b28_9115_7127.pdf
2014-01-08sanitize crypt revision in pdf_new_cryptSimon Bünzli
This correctly enables the sanitization of the key length needed for 90db34f64037e2a8a5c3b6a518ba4153_asan_heap-oob_9b117e_1197_1802.pdf
2014-01-08sanitize values in fz_open_predictSimon Bünzli
This fixes a NULL pointer dereference in 2192b04848b2d8210d1a33e3ddeb2742_asan_heap-oob_a5a57d_2745_2844.pdf Also, replace MAXC with FZ_MAX_COLORS.
2014-01-07Introduce 'document handlers'.Robin Watts
We define a document handler for each file type (2 in the case of PDF, one to handle files with the ability to 'run' them, and one without). We then register these handlers with the context at startup, and then call fz_open_document... as usual. This enables people to select the document types they want at will (and even to extend the library with more document types should they wish).
2014-01-06Bug 694869: Fix indetermisms with broken PNG files.Robin Watts
This bug shows 2 problems with our data handling. Firstly, if a zip file entry has less data in the stream than it is declared to have, we would leave the end of the data uninitialised. We now put out a warning, and blank it with zeros. Secondly, if the PNG decompression fails to decode enough data, we don't notice. Now we give a warning and blank the remaining pixels.
2014-01-06reuse JBIG2GlobalsSimon Bünzli
Certain optimized documents use a rather large common symbol dictionary for all JBIG2 images. Caching these JBIG2Globals speeds up loading and rendering of such documents.
2014-01-06show jbig2dec warnings/errors in stderrSimon Bünzli
This helps debugging issues with JBIG2 images. Conflicts: source/fitz/filter-jbig2.c
2014-01-06add stub files for JPEG-XR supportSimon Bünzli
See SumatraPDF's repo for a Windows-only implementation using WIC.
2014-01-06tolerate slightly broken page treesSimon Bünzli
At https://code.google.com/p/sumatrapdf/issues/detail?id=2460 , there's a file with missing /Type keys in the page tree nodes. In that case, leaf nodes and intermediary nodes have to be distinguished in a different way.
2014-01-06fix MSVC warnings C4054 and C4152Simon Bünzli
These warnings are caused by casting function pointers to void* instead of proper function types.
2014-01-06fix various MSVC warningsSimon Bünzli
Some warnings we'd like to enable for MuPDF and still be able to compile it with warnings as errors using MSVC (2008 to 2013): * C4115: 'timeval' : named type definition in parentheses * C4204: nonstandard extension used : non-constant aggregate initializer * C4295: 'hex' : array is too small to include a terminating null character * C4389: '==' : signed/unsigned mismatch * C4702: unreachable code * C4706: assignment within conditional expression Also, globally disable C4701 which is frequently caused by MSVC not being able to correctly figure out fz_try/fz_catch code flow. And don't define isnan for VS2013 and later where that's no longer needed.
2014-01-02Add rebinding for fz_devices and fz_documentsRobin Watts
The SVG device needs rebinding as it holds a file. The PDF device needs to rebind the underlying pdf document. All documents need to rebind their underlying streams.
2014-01-02Add rebinding for fz_streams.Robin Watts
2014-01-02Add rebinding for fz_output.Robin Watts
2014-01-02Bug 694585: Further improve mesh rendering timesRobin Watts
Add a cached color converter mechanism. Use this for rendering meshes to speed repeated conversions. This reduces a (release build to ppm at default resolution) run from 23.5s to 13.2 seconds.
2014-01-02Bug 694585: Slow rendering of meshesRobin Watts
In the existing code for meshes, we decompose the mesh down into quads (or triangles) and then call a process routine to actually do the work. This process routine typically maps each vertexes position/color and plots it. As each vertex is used several times by neighbouring patches, this results in each vertex being processed several times. The fix in this commit is therefore to break the processing into 'prepare' and 'process' phases. Each vertex is 'prepared' before being used in the 'process' phase. This cuts the number of prepare operations in half. In testing, this reduced the time for a (release build, generating ppm at default resolution) run from 33.4s to 23.5s.
2014-01-02Improve PDF repair logic.Robin Watts
When we meet a broken PDF file, we attempt to repair it. We do this by reading tokens from the file and attempting to interpret them as a normal PDF stream. Unfortunately, if the file is corrupt enough so that we start to read from the middle of a stream, and we happen to hit an '(' character, we can go into string reading mode. We can then end up skipping over vast swathes of file that we could otherwise repair. We fix this here by using a new version of the pdf_lex function that refuses to ever return a string. This means we may take more time over skipping things than we did before, but are less likely to skip stuff. We also tweak other parts of the pdf repair logic here. If we hit a badly formed piece of data, clear the num/gen we have stored so that the next plausible piece we get does not get assigned to a random object number.
2014-01-02Cull code unused as a result of the "tolerate inline images..." fix.Robin Watts
Remove code that's not used any more as a result of the previous fix, plus some code that was unused anyway.
2014-01-02fix memory leak in pdf_repair_xrefSimon Bünzli
The 0 null object is leaked if a document refers to 0 0 obj before requiring a delayed reparation (seen e.g. with 3324.pdf.asan.3.2585).
2014-01-02Fix memory leak in pdf_xref_size_from_old_trailer.Robin Watts
Thanks to Simon for spotting the original problem. This is a slight tweak on the patch he supplied.
2014-01-02Bug 694569: suspicious for loop in pdf-device.cPaul Gardiner
Replace an explicit i = i by a comment in a for loop where i is already at the correct starting value.
2014-01-02Bug 694729: Rounding the InkPaul Gardiner
Use round caps and joins so as to better match the result of drawing, and also so that single dots display. Thanks to Michael Cadilhac for the suggestion.
2014-01-01Bug 693320: Avoid unaligned accesses in SHA routines.Robin Watts
Avoid unnecessary copies. Minimise calls to isbigendian.
2014-01-01tolerate inline images without EOF markersSimon Bünzli
This is required for e.g. 1980_-_compressed_inline_image.pdf and Bug690300.pdf .
2014-01-01don't fail on invalid object streamsSimon Bünzli
At https://code.google.com/p/sumatrapdf/issues/detail?id=2436 , there's a document with an empty xref section which since recently causes a repair to be triggered. Repairs then stop when pdf_repair_obj_stms fails on an object which isn't even required for the document to render. Such broken object streams should rather be ignored same as broken objects are ignored in pdf_init_document.
2013-12-30Bug 694564: Move pdf_lookup_page_obj to be iterativeRobin Watts
Avoid recursion to avoid stack overflows.
2013-12-24Bug 694587: Fix pattern repeat calculationRobin Watts
The pattern repeat calculation should be done in pattern space, but one of the arguments in the calculation was being taken from device space. Fix this. Also only apply the bias in the case where the bias would make it larger. 173 progressions.
2013-12-24Bug 694810: Implement late file repair for PDFs.Robin Watts
Currently, if we spot a bad xref as we are reading a PDF in, we can repair that PDF by doing a long exhaustive read of the file. This reconstructs the information that was in the xref, and the file can be opened (and later saved) as normal. If we hit an object that is not in the expected place however, we cannot trigger a repair at that point - so xrefs with duff offsets in (within the bounds of the file) will never be repaired. This commit solves that by triggering a repair (just once) whenever we fail to parse an object in the expected place.
2013-12-23Bug 694712: Do not create empty Contents stream for new pages.Robin Watts
Empty Contents streams are not valid - they need a length at least. The alternative approach would be to put /Length 0 and update it later.
2013-12-23Bug 694715: Fix typo in error messageRobin Watts
Thanks to Michael Cadilhac for spotting this.
2013-12-23Bug 694749: Fix transformation of hinted glyphsRobin Watts
Simple typo. Thanks to Alexander Monakov for spotting this.
2013-12-23Bug 694794: Fix blendmode use in pdf device.Robin Watts
Previously we were setting blendmode in the created form XObjects transparency group definition. This didn't work as PDF readers don't look for it there. Now we set it in the calling stream's resources, and set it before calling the group.
2013-12-23Bug 694770: Fix typo in error message.Robin Watts
Thanks to Makoto Fujiwara for spotting this.
2013-12-19Solve subpixel rendering problems with 270 degree rotationsRobin Watts
It seems that (int)-98.5 = 98, not -99. Use floorf instead.
2013-12-17Bug 694810: Fix crash when clicking on mupdf window after failed page load.Robin Watts
If we have a NULL page, don't attempt to pass events to it.
2013-12-17Remove fz_context from pdf_cryptRobin Watts
Unused field. Also tweak some comments for clarity.
2013-12-16javascript: fix missing type destructionPaul Gardiner
2013-12-16JavaScriptCore-based implementation of the MuPDF JS engine APIPaul Gardiner
2013-11-28Bug 694127: Valgrind fix for pdf_decode_cmapRobin Watts
A poorly formed string can cause us to overrun the end of the buffer. Now we check the end of the string at each stage to avoid this.