Jonas Jenwald d0c4bbd828 [api-minor] Validate the /Pages-tree /Count entry during document initialization (issue 14303)
*This patch basically extends the approach from PR 10392, by also checking the last page.*

Currently, in e.g. the `Catalog.numPages`-getter, we're simply assuming that if the /Pages-tree has an *integer* /Count entry it must also be correct/valid.
As can be seen in the referenced PDF documents, that entry may be completely bogus which causes general parsing to breaking down elsewhere in the worker-thread (and hanging the browser).

Rather than hoping that the /Count entry is correct, similar to all other data found in PDF documents, we obviously need to validate it. This turns out to be a little less straightforward than one would like, since the only way to do this (as far as I know) is to parse the *entire* /Pages-tree and essentially counting the pages.
To avoid doing that for all documents, this patch tries to take a short-cut by checking if the last page (based on the /Count entry) can be successfully fetched. If so, we assume that the /Count entry is correct and use it as-is, otherwise we'll iterate through (potentially) the *entire* /Pages-tree to determine the number of pages.

Unfortunately these changes will have a number of *somewhat* negative side-effects, please see a possibly incomplete list below, however I cannot see a better way to address this bug.
 - This will slow down initial loading/rendering of all documents, at least by some amount, since we now need to fetch/parse more of the /Pages-tree in order to be able to access the *last* page of the PDF documents.
 - For poorly generated PDF documents, where the entire /Pages-tree only has *one* level, we'll unfortunately need to fetch/parse the *entire* /Pages-tree to get to the last page. While there's a cache to help reduce repeated data lookups, this will affect initial loading/rendering of *some* long PDF documents,
 - This will affect the `disableAutoFetch = true` mode negatively, since we now need to fetch/parse more data during document initialization. While the `disableAutoFetch = true` mode should still be helpful in larger/longer PDF documents, for smaller ones the effect/usefulness may unfortunately be lost.

As one *small* additional bonus, we should now also be able to support opening PDF documents where the /Pages-tree /Count entry is completely invalid (e.g. contains a non-integer value).

Fixes two of the issues listed in issue 14303, namely the `poppler-67295-0.pdf` and `poppler-85140-0.pdf` documents.
2021-11-27 21:57:35 +01:00
..
2013-05-31 14:13:23 -07:00
2013-03-11 10:23:47 -07:00
2016-04-11 08:02:06 -05:00
2021-04-10 19:13:28 +02:00
2013-11-03 07:29:29 -06:00
2013-07-11 13:33:29 -05:00
2013-11-18 07:48:06 -06:00
2013-11-13 13:45:59 -06:00
2015-10-04 15:45:24 +02:00
2016-04-11 08:02:06 -05:00
2013-10-13 19:55:42 +03:00
2011-06-23 09:10:06 -07:00
2021-06-08 10:37:26 +02:00
2011-12-12 21:42:39 -06:00
2012-03-10 19:12:33 -08:00
2015-11-06 10:55:43 -06:00
2013-11-01 19:05:17 -05:00
2012-10-13 14:21:59 -05:00
2012-12-14 12:44:39 -08:00
2013-02-28 22:32:43 +02:00
2013-11-02 17:07:13 -05:00
2013-08-11 10:35:56 +02:00
2013-12-19 18:38:44 +01:00
2020-08-08 11:50:19 +02:00
2014-03-18 14:10:44 +01:00
2014-04-10 19:22:13 -05:00
2014-04-11 09:55:39 -07:00
2014-04-17 07:52:33 -05:00
2014-09-09 08:29:31 -05:00
2014-12-17 22:46:47 +01:00
2014-12-18 21:26:02 +01:00
2014-12-17 22:42:06 +01:00
2015-02-10 00:16:54 +01:00
2015-11-03 09:03:08 -06:00
2017-01-10 16:42:43 +00:00
2017-04-10 16:18:08 -07:00
2017-04-05 15:17:38 -07:00
2021-05-12 11:42:08 -07:00
2017-08-03 22:19:36 -07:00
2018-09-02 21:23:09 +02:00
2018-09-02 21:23:09 +02:00
2018-09-02 21:23:09 +02:00
2021-10-17 16:27:05 +02:00
2021-10-17 16:27:05 +02:00
2021-10-17 16:27:05 +02:00
2021-10-17 16:27:05 +02:00
2021-10-17 16:27:05 +02:00
2021-09-23 13:05:18 +02:00
2014-01-27 20:35:51 -06:00
2015-09-05 12:51:05 +02:00
2015-10-16 18:54:18 +02:00
2015-10-16 18:54:18 +02:00
2013-06-30 03:52:30 +05:30
2011-08-06 14:41:18 -07:00
2012-01-11 20:14:49 -06:00
2011-06-26 09:15:33 -05:00
2011-12-18 17:28:25 -08:00
2012-03-17 17:35:04 -05:00
2011-10-04 16:18:39 +01:00
2011-06-23 09:10:06 -07:00
2013-02-15 03:53:34 +09:00
2021-11-27 19:30:12 +01:00
2014-09-03 21:57:57 +02:00
2012-01-17 20:50:49 -08:00