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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb1a2ebe9b89b1c97bcfe6a9227bbdc9b8627458900347ac0965784f4d95f83f
4
- data.tar.gz: 294eeaa8e9d9926debf2d28d83c8cd419f5685a88b9d23c378fa783fce2d62cb
3
+ metadata.gz: 85c063a63af9729acc10a54ef53fba69d73b75f1c06ff0e6de246df920e17dd9
4
+ data.tar.gz: dcea10d0ccfe66282c92e6bb41c1d57927d525e1618753d598a910546c8a8e82
5
5
  SHA512:
6
- metadata.gz: e2284d3397a856d895b8ec2c83b3ead95ba11a571df90f9fdaed7cd83e4880004ea04150df9205a534d203ae5a1958977a7755ad9f06d622c4f38ae43c0823ab
7
- data.tar.gz: 2d6b454f78f7b319240fc062429c32f87ed350ab64a596e7b5050abe65b4e8b4bd9c3551cb87a699219fbd484b5c7670c9662674d9aa5dc8ef800dbe70a273c2
6
+ metadata.gz: 4f1d468375c4ce336e55a09d897de9a8c95babcfa1b4441cc04a9dc712435c64906016647baa030f5695f9434d18214c30bca746f245b53a69321139f63256b9
7
+ data.tar.gz: 1f1895ca7ad46bae1bf33790d4c8daa7f72adfcc00cc26e1611b7ece64d7a5a76e7f1e06be4022bb58f5dbd84154e9846cb4feb94f727c9abe99f5b7c8b87fcf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.19.3 - 2021-12-14
2
+
3
+ ### Fixed
4
+
5
+ * Handling of invalid files where the "startxref" keyword and its value are on
6
+ the same line
7
+
8
+
1
9
  ## 0.19.2 - 2021-12-14
2
10
 
3
11
  ### Fixed
@@ -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
- unless eof_index
354
+ if !eof_index
354
355
  eof_not_found = true
355
- next
356
- end
357
- unless eof_index >= 2 && lines[eof_index - 2].strip == "startxref"
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
- next
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 = lines[eof_index - 1].to_i
378
+ @startxref_offset = startxref_offset
374
379
  end
375
380
 
376
381
  # Returns the reconstructed revision.
@@ -37,6 +37,6 @@
37
37
  module HexaPDF
38
38
 
39
39
  # The version of HexaPDF.
40
- VERSION = '0.19.2'
40
+ VERSION = '0.19.3'
41
41
 
42
42
  end
@@ -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
@@ -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.2)>>
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.2)>>
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.2
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-13 00:00:00.000000000 Z
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdparse