Fix 594 use null id when encrypted but no id given (#595)

Co-authored-by: Pieter Marsman <pietermarsman@gmail.com>
pull/600/head^2
Richard Millson 2021-08-29 15:32:14 -04:00 committed by GitHub
parent 234c466372
commit a70f08818d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 2 deletions

View File

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Support for Paeth PNG filter compression (predictor value = 4) ([#537](https://github.com/pdfminer/pdfminer.six/pull/537))
### Fixed
- `KeyError` when `'Encrypt'` but not `'ID'` present in `trailer` ([#594](https://github.com/pdfminer/pdfminer.six/pull/594))
- Fix issue of ValueError and KeyError rasied in PDFdocument and PDFparser ([#573](https://github.com/pdfminer/pdfminer.six/pull/574))
- Fix issue of TypeError: cannot unpack non-iterable PDFObjRef object, when unpacking the value of 'DW2' ([#529](https://github.com/pdfminer/pdfminer.six/pull/529))
- `PermissionError` when creating temporary filepaths on windows when running tests ([#469](https://github.com/pdfminer/pdfminer.six/issues/469))

View File

@ -583,7 +583,14 @@ class PDFDocument:
continue
# If there's an encryption info, remember it.
if 'Encrypt' in trailer:
self.encryption = (list_value(trailer['ID']),
if 'ID' in trailer:
id_value = list_value(trailer['ID'])
else:
# Some documents may not have a /ID, use two empty
# byte strings instead. Solves
# https://github.com/pdfminer/pdfminer.six/issues/594
id_value = (b'', b'')
self.encryption = (id_value,
dict_value(trailer['Encrypt']))
self._initialize_password(password)
if 'Info' in trailer:

Binary file not shown.

View File

@ -1,4 +1,4 @@
from nose.tools import raises
from nose.tools import assert_equal, raises
from helpers import absolute_sample_path
from pdfminer.pdfdocument import PDFDocument
@ -14,3 +14,14 @@ class TestPdfDocument(object):
parser = PDFParser(in_file)
doc = PDFDocument(parser)
doc.getobj(0)
def test_encrypted_no_id(self):
# Some documents may be encrypted but not have an /ID key in
# their trailer. Tests
# https://github.com/pdfminer/pdfminer.six/issues/594
path = absolute_sample_path('encryption/encrypted_doc_no_id.pdf')
with open(path, 'rb') as fp:
parser = PDFParser(fp)
doc = PDFDocument(parser)
assert_equal(doc.info,
[{'Producer': b'European Patent Office'}])