Fix assertionerror when dumping pdf with reference to objid 0 (#318)

Fixes #94 
Added: test to get check if `PDFObjectNotFound` error is raised if objid 0 is requested.
pull/319/head
Pieter Marsman 2019-10-25 22:49:58 +02:00 committed by GitHub
parent 5516c8147c
commit a238a19999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- Support for extracting JBIG2 encoded images ([#311](https://github.com/pdfminer/pdfminer.six/pull/311) and [#46](https://github.com/pdfminer/pdfminer.six/pull/46))
### Fixed
- Unhandled AssertionError when dumping pdf containing reference to object id 0 ([#318](https://github.com/pdfminer/pdfminer.six/pull/318))
## [20191020] - 2019-10-20
### Deprecated

View File

@ -671,7 +671,11 @@ class PDFDocument(object):
# can raise PDFObjectNotFound
def getobj(self, objid):
assert objid != 0
"""Get object from PDF
:raises PDFException if PDFDocument is not initialized
:raises PDFObjectNotFound if objid does not exist in PDF
"""
if not self.xrefs:
raise PDFException('PDFDocument is not initialized')
log.debug('getobj: objid=%r', objid)

15
tests/test_pdfdocument.py Normal file
View File

@ -0,0 +1,15 @@
from nose.tools import raises
from pdfminer.pdftypes import PDFObjectNotFound
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfparser import PDFParser
class TestPdfDocument(object):
@raises(PDFObjectNotFound)
def test_get_zero_objid_raises_pdfobjectnotfound(self):
with open('../samples/simple1.pdf', 'rb') as in_file:
parser = PDFParser(in_file)
doc = PDFDocument(parser)
doc.getobj(0)