Skip to content

Commit

Permalink
Cleanup exception handling for jbig2 global streams
Browse files Browse the repository at this point in the history
  • Loading branch information
pietermarsman committed Jan 23, 2022
1 parent cf0b47b commit bb97725
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pdfminer/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,12 @@ def export_image(self, image: LTImage) -> str:
elif is_jbig2:
input_stream = BytesIO()
global_streams = self.jbig2_global(image)
if len(global_streams) > 1:
msg = 'There should never be more than one JBIG2Globals ' \
'associated with a JBIG2 embedded image'
raise ValueError(msg)
if len(global_streams) == 1:
global_stream, = global_streams
input_stream.write(global_stream.get_data().rstrip(b'\n'))
elif len(global_streams) > 1:
raise ValueError('There should never be more than one '
'JBIG2Globals associated with a JBIG2 '
'embedded image')
input_stream.write(global_streams[0].get_data().rstrip(b'\n'))
input_stream.write(image.stream.get_data())
input_stream.seek(0)
reader = JBIG2StreamReader(input_stream)
Expand Down

0 comments on commit bb97725

Please sign in to comment.