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
parent
5516c8147c
commit
a238a19999
|
@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
### Added
|
### 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))
|
- 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
|
## [20191020] - 2019-10-20
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
|
@ -671,7 +671,11 @@ class PDFDocument(object):
|
||||||
|
|
||||||
# can raise PDFObjectNotFound
|
# can raise PDFObjectNotFound
|
||||||
def getobj(self, objid):
|
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:
|
if not self.xrefs:
|
||||||
raise PDFException('PDFDocument is not initialized')
|
raise PDFException('PDFDocument is not initialized')
|
||||||
log.debug('getobj: objid=%r', objid)
|
log.debug('getobj: objid=%r', objid)
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue