hexapdf 0.15.6 → 0.15.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bcffb10babdbf723a478ea40721d9515222adf8d12ba9bd799f7b95fa66bc408
4
- data.tar.gz: d5929900ab1b010a39964edc366ea223ef8a2ee9bcd1e9a5873874b4d5a8ecc5
3
+ metadata.gz: 1385aca5e91916034a5494142b4c88e51de46d2d13b79ddaed9494c74808793a
4
+ data.tar.gz: 4fee33d3c96e74c00565ac6211901f39c0242cd2e0926f0760be7bfb18fe7f12
5
5
  SHA512:
6
- metadata.gz: d12bbd49204c28675d399477ce0249140bf6ead3fe9332541128802f0edc3ebb2b187752b464b9acd3b71ca4ce6cb5cba33caf19282bd5a15020cec3c6e20297
7
- data.tar.gz: 8df3586c8069db615bf317f22b28069f4bfd1395d31c285bb5c4a63b1b46ec60b088082a5d461adafd590718df6307734361e1e61fe3210009d158fc95c558be
6
+ metadata.gz: 3fa1454ec6821500c1f94981ad17efcbf36f125a29870a62ad0d626fe65cd35bb7ef6426021daba3b2554dcbd20f1ce6efc4d93c1d4d8b5303d6063eb27804fb
7
+ data.tar.gz: 8f2c3de849fed113c6f4fe7494312a202a872f7364052b584a38352315a4a358f135beea8dd951c29d2dbd3b842c4eefe3892ed3d9bb3c24e6875cdbb0c59123
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.15.7 - 2021-07-17
2
+
3
+ ### Fixed
4
+
5
+ * Infinite loop while parsing PDF array due to missing closing bracket
6
+ * Handling of invalid files with missing or corrupted trailer dictionary
7
+
8
+
1
9
  ## 0.15.6 - 2021-07-16
2
10
 
3
11
  ### Fixed
@@ -447,6 +447,15 @@ module HexaPDF
447
447
 
448
448
  if !trailer || trailer.empty?
449
449
  _, trailer = load_revision(startxref_offset) rescue nil
450
+ unless trailer
451
+ xref.each do |_oid, _gen, xref_entry|
452
+ obj, * = parse_indirect_object(xref_entry.pos) rescue nil
453
+ if obj.kind_of?(Hash) && obj[:Type] == :Catalog
454
+ trailer = {Root: HexaPDF::Reference.new(xref_entry.oid, xref_entry.gen)}
455
+ break
456
+ end
457
+ end
458
+ end
450
459
  unless trailer
451
460
  @in_reconstruct_revision = false
452
461
  raise_malformed("Could not reconstruct malformed PDF because trailer was not found", pos: 0)
@@ -55,6 +55,9 @@ module HexaPDF
55
55
 
56
56
  # This object is returned when there are no more tokens to read.
57
57
  NO_MORE_TOKENS = ::Object.new
58
+ def NO_MORE_TOKENS.to_s
59
+ "EOS - no more tokens"
60
+ end
58
61
 
59
62
  # Characters defined as whitespace.
60
63
  #
@@ -384,7 +387,11 @@ module HexaPDF
384
387
  result = []
385
388
  while true
386
389
  obj = next_object(allow_end_array_token: true)
387
- break if obj.equal?(TOKEN_ARRAY_END)
390
+ if obj.equal?(TOKEN_ARRAY_END)
391
+ break
392
+ elsif obj.equal?(NO_MORE_TOKENS)
393
+ raise HexaPDF::MalformedPDFError.new("Unclosed array found", pos: pos)
394
+ end
388
395
  result << obj
389
396
  end
390
397
  result
@@ -403,7 +410,8 @@ module HexaPDF
403
410
  key = next_token
404
411
  break if key.equal?(TOKEN_DICT_END)
405
412
  unless key.kind_of?(Symbol)
406
- raise HexaPDF::MalformedPDFError.new("Dictionary keys must be PDF name objects", pos: pos)
413
+ raise HexaPDF::MalformedPDFError.new("Dictionary keys must be PDF name objects, " \
414
+ "found '#{key}'", pos: pos)
407
415
  end
408
416
 
409
417
  val = next_object
@@ -37,6 +37,6 @@
37
37
  module HexaPDF
38
38
 
39
39
  # The version of HexaPDF.
40
- VERSION = '0.15.6'
40
+ VERSION = '0.15.7'
41
41
 
42
42
  end
@@ -161,6 +161,21 @@ module CommonTokenizerTests
161
161
  assert_raises(HexaPDF::MalformedPDFError) { @tokenizer.next_object }
162
162
  end
163
163
 
164
+ it "next_object: fails for an array without closing bracket, encountering EOS" do
165
+ create_tokenizer("[1 2")
166
+ exception = assert_raises(HexaPDF::MalformedPDFError) { @tokenizer.next_object }
167
+ assert_match(/Unclosed array found/, exception.message)
168
+ end
169
+
170
+ it "next_object: fails for a dictionary without closing bracket, encountering EOS" do
171
+ create_tokenizer("<</Name 5")
172
+ exception = assert_raises(HexaPDF::MalformedPDFError) { @tokenizer.next_object }
173
+ assert_match(/must be PDF name objects.*EOS/, exception.message)
174
+ create_tokenizer("<</Name 5 /Other")
175
+ exception = assert_raises(HexaPDF::MalformedPDFError) { @tokenizer.next_object }
176
+ assert_match(/must be PDF name objects.*EOS/, exception.message)
177
+ end
178
+
164
179
  it "returns the correct position on operations" do
165
180
  create_tokenizer("hallo du" << " " * 50000 << "hallo du")
166
181
  @tokenizer.next_token
@@ -619,7 +619,12 @@ describe HexaPDF::Parser do
619
619
  assert_equal({Size: 1}, @parser.reconstructed_revision.trailer.value)
620
620
  end
621
621
 
622
- it "fails if no trailer is found and the trailer specified at the startxref position is not valid" do
622
+ it "constructs a trailer with a /Root entry if no valid trailer was found" do
623
+ create_parser("1 0 obj\n<</Type /Catalog/Pages 2 0 R>>\nendobj\nxref trailer <</Size 1/Prev 5\n%%EOF")
624
+ assert_equal({Root: HexaPDF::Reference.new(1, 0)}, @parser.reconstructed_revision.trailer.value)
625
+ end
626
+
627
+ it "fails if no valid trailer is found and couldn't be constructed" do
623
628
  create_parser("1 0 obj\n5\nendobj\nquack trailer <</Size 1>>\nstartxref\n22\n%%EOF")
624
629
  assert_raises(HexaPDF::MalformedPDFError) { @parser.reconstructed_revision.trailer }
625
630
  end
@@ -40,7 +40,7 @@ describe HexaPDF::Writer do
40
40
  219
41
41
  %%EOF
42
42
  3 0 obj
43
- <</Producer(HexaPDF version 0.15.6)>>
43
+ <</Producer(HexaPDF version 0.15.7)>>
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.15.6)>>
75
+ <</Producer(HexaPDF version 0.15.7)>>
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.15.6
4
+ version: 0.15.7
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-07-16 00:00:00.000000000 Z
11
+ date: 2021-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdparse