From 115d77b484162276b93cec4ecc3ddc67aab092f7 Mon Sep 17 00:00:00 2001 From: xiaowk5516 <59595896+xiaowk5516@users.noreply.github.com> Date: Wed, 16 Jun 2021 19:31:26 +0800 Subject: [PATCH] Assert non-premature end of JPEG images (#3638) * premature end of JPEG images * PEP8 reformat Co-authored-by: Glenn Jocher --- utils/datasets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/datasets.py b/utils/datasets.py index 20109e739c02..a1a8fa8f32a9 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -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