hexapdf 0.19.2 → 0.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/hexapdf/parser.rb +14 -9
- data/lib/hexapdf/version.rb +1 -1
- data/test/hexapdf/test_parser.rb +12 -0
- data/test/hexapdf/test_writer.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85c063a63af9729acc10a54ef53fba69d73b75f1c06ff0e6de246df920e17dd9
|
4
|
+
data.tar.gz: dcea10d0ccfe66282c92e6bb41c1d57927d525e1618753d598a910546c8a8e82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f1d468375c4ce336e55a09d897de9a8c95babcfa1b4441cc04a9dc712435c64906016647baa030f5695f9434d18214c30bca746f245b53a69321139f63256b9
|
7
|
+
data.tar.gz: 1f1895ca7ad46bae1bf33790d4c8daa7f72adfcc00cc26e1611b7ece64d7a5a76e7f1e06be4022bb58f5dbd84154e9846cb4feb94f727c9abe99f5b7c8b87fcf
|
data/CHANGELOG.md
CHANGED
data/lib/hexapdf/parser.rb
CHANGED
@@ -342,7 +342,8 @@ module HexaPDF
|
|
342
342
|
step_size = 1024
|
343
343
|
pos = @io.pos
|
344
344
|
eof_not_found = pos == 0
|
345
|
-
startxref_missing = false
|
345
|
+
startxref_missing = startxref_mangled = false
|
346
|
+
startxref_offset = nil
|
346
347
|
|
347
348
|
while pos != 0
|
348
349
|
@io.pos = [pos - step_size, 0].max
|
@@ -350,27 +351,31 @@ module HexaPDF
|
|
350
351
|
lines = @io.read(step_size + 40).split(/[\r\n]+/)
|
351
352
|
|
352
353
|
eof_index = lines.rindex {|l| l.strip == '%%EOF' }
|
353
|
-
|
354
|
+
if !eof_index
|
354
355
|
eof_not_found = true
|
355
|
-
|
356
|
-
|
357
|
-
|
356
|
+
elsif lines[eof_index - 1].strip =~ /\Astartxref\s(\d+)\z/
|
357
|
+
startxref_offset = $1.to_i
|
358
|
+
startxref_mangled = true
|
359
|
+
break # we found it even if it the syntax is not entirely correct
|
360
|
+
elsif eof_index < 2 || lines[eof_index - 2].strip != "startxref"
|
358
361
|
startxref_missing = true
|
359
|
-
|
362
|
+
else
|
363
|
+
startxref_offset = lines[eof_index - 1].to_i
|
364
|
+
break # we found it
|
360
365
|
end
|
361
|
-
|
362
|
-
break # we found the startxref offset
|
363
366
|
end
|
364
367
|
|
365
368
|
if eof_not_found
|
366
369
|
maybe_raise("PDF file trailer with end-of-file marker not found", pos: pos,
|
367
370
|
force: !eof_index)
|
371
|
+
elsif startxref_mangled
|
372
|
+
maybe_raise("PDF file trailer keyword startxref on same line as value", pos: pos)
|
368
373
|
elsif startxref_missing
|
369
374
|
maybe_raise("PDF file trailer is missing startxref keyword", pos: pos,
|
370
375
|
force: eof_index < 2 || lines[eof_index - 2].strip != "startxref")
|
371
376
|
end
|
372
377
|
|
373
|
-
@startxref_offset =
|
378
|
+
@startxref_offset = startxref_offset
|
374
379
|
end
|
375
380
|
|
376
381
|
# Returns the reconstructed revision.
|
data/lib/hexapdf/version.rb
CHANGED
data/test/hexapdf/test_parser.rb
CHANGED
@@ -338,6 +338,11 @@ describe HexaPDF::Parser do
|
|
338
338
|
assert_equal(5, @parser.startxref_offset)
|
339
339
|
end
|
340
340
|
|
341
|
+
it "handles the case of startxref and its value being on the same line" do
|
342
|
+
create_parser("startxref 5\n%%EOF")
|
343
|
+
assert_equal(5, @parser.startxref_offset)
|
344
|
+
end
|
345
|
+
|
341
346
|
it "fails even in big files when nothing is found" do
|
342
347
|
create_parser("\nhallo" * 5000)
|
343
348
|
exp = assert_raises(HexaPDF::MalformedPDFError) { @parser.startxref_offset }
|
@@ -366,6 +371,13 @@ describe HexaPDF::Parser do
|
|
366
371
|
exp = assert_raises(HexaPDF::MalformedPDFError) { @parser.startxref_offset }
|
367
372
|
assert_match(/end-of-file marker not found/, exp.message)
|
368
373
|
end
|
374
|
+
|
375
|
+
it "fails on strict parsing if the startxref is on the same line as its value" do
|
376
|
+
@document.config['parser.on_correctable_error'] = proc { true }
|
377
|
+
create_parser("startxref 5\n%%EOF")
|
378
|
+
exp = assert_raises(HexaPDF::MalformedPDFError) { @parser.startxref_offset }
|
379
|
+
assert_match(/startxref on same line/, exp.message)
|
380
|
+
end
|
369
381
|
end
|
370
382
|
|
371
383
|
describe "file_header_version" do
|
data/test/hexapdf/test_writer.rb
CHANGED
@@ -40,7 +40,7 @@ describe HexaPDF::Writer do
|
|
40
40
|
219
|
41
41
|
%%EOF
|
42
42
|
3 0 obj
|
43
|
-
<</Producer(HexaPDF version 0.19.
|
43
|
+
<</Producer(HexaPDF version 0.19.3)>>
|
44
44
|
endobj
|
45
45
|
xref
|
46
46
|
3 1
|
@@ -72,7 +72,7 @@ describe HexaPDF::Writer do
|
|
72
72
|
141
|
73
73
|
%%EOF
|
74
74
|
6 0 obj
|
75
|
-
<</Producer(HexaPDF version 0.19.
|
75
|
+
<</Producer(HexaPDF version 0.19.3)>>
|
76
76
|
endobj
|
77
77
|
2 0 obj
|
78
78
|
<</Length 10>>stream
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexapdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.19.
|
4
|
+
version: 0.19.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Leitner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cmdparse
|