Commit Graph

7 Commits

Author SHA1 Message Date
Eliot Jones
0afe021ad3 move file parsing to single-pass static methods (#1102)
* move file parsing to single-pass static methods

for the file 0002973.pdf in the test corpus we need to completely overhaul
how initial xref parsing is done since we need to locate the xref stream by
brute-force and this is currently broken. i wanted to take this opportunity to
change the logic to be more imperative and less like the pdfbox methods with
instance data and classes.

currently the logic is split between the xref offset validator and parser methods
and we call the validator logic twice, followed by brute-force searching again
in the actual parser. we're going to move to a single method that performs
the following steps:

1. find the first (from the end) occurrence of "startxref" and pull out the location
in bytes. this will also support "startref" since some files in the wild have that
2. go to that offset if found and parse the chain of tables or streams by /prev
reference
3. if any element in step 2 fails then we perform a single brute-force over the
entire file and like pdfbox treat later in file-length xrefs as the ultimate arbiter
of the object positions. while we do this we potentially can capture the actual
object offsets since the xref positions are probably incorrect too.

the aim with this is to avoid as much seeking and re-reading of bytes as
possible. while this won't technically be single-pass it gets us much closer. it
also removes the more strict logic requiring a "startxref" token to exist and be
valid, since we can repair this by brute-force anyway.

we will surface as much information as possible from the static method so that
we could in future support an object explorer ui for pdfs.

this will also be more resilient to invalid xref formats with e.g. comment tokens
or missing newlines.

* move more parsing to the static classes

* plumb through the new parsing results

* plug in new parser and remove old classes, port tests to new classes

* update tests to reflect logic changes

* apply correction when file header has offset

* ignore console runner launch settings

* skip offsets outside of file bounds

* fix parsing tables missing a line break

* use brute forced locations if they're already present

* only treat line breaks and spaces as whitespace for stream content

* address review comments

---------

Co-authored-by: BobLd <38405645+BobLd@users.noreply.github.com>
2025-09-02 19:41:00 +01:00
Matěj Štágl
ba8e1e1b45 fix #1017
fix test name
2025-03-26 18:59:39 +00:00
Jacob O'Toole
e9139a2b56 Add doxygen-docs config 2022-02-15 11:58:00 +00:00
Eliot Jones
e353fc69e8 ignore console runner launchsettings
since the console runner is used to run through a test directory stored
locally its value will be different for each developer. we'll ignore it
to avoid it getting committed accidentally
2021-05-30 13:20:55 -04:00
Eliot Jones
ec060ae81b add hardcoded switch branches for more content operations
also adds a gitignore entry for the 'benchmark' subfolder in tools where custom benchmarking applications can be built and run without being added to source control.
2019-12-24 23:12:04 +00:00
Eliot Jones
6b11d570c9 add a different way of running open cover since it doesn't work on app veyor 2017-12-05 22:44:37 +00:00
Eliot Jones
2897051075 Move the code from the forked version to clean repository 2017-11-09 19:14:09 +00:00