Skip to content

Commit

Permalink
Assert non-premature end of JPEG images (ultralytics#3638)
Browse files Browse the repository at this point in the history
* premature end of JPEG images

* PEP8 reformat

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
xiaowk5516 and glenn-jocher committed Jun 16, 2021
1 parent 0319d63 commit 115d77b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,10 @@ def verify_image_label(args):
shape = exif_size(im) # image size
assert (shape[0] > 9) & (shape[1] > 9), f'image size {shape} <10 pixels'
assert im.format.lower() in img_formats, f'invalid image format {im.format}'
if im.format.lower() in ('jpg', 'jpeg'):
with open(im_file, 'rb') as f:
f.seek(-2, 2)
assert f.read() == b'\xff\xd9', 'corrupted JPEG'

# verify labels
segments = [] # instance segments
Expand Down

0 comments on commit 115d77b

Please sign in to comment.