This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mvignali
Recipients Claudiu.Popa, ezio.melotti, intgr, jcea, joril, kovid, mvignali, r.david.murray, vstinner
Date 2014-06-21.18:44:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1403376262.23.0.0860237004994.issue16512@psf.upfronthosting.co.za>
In-reply-to
Content
I'm okay with just testing the first two bytes, it's the method we currently use for our
internal tools.

But maybe it can be interesting, to add another test, in order to detect incomplete file
(created when a camera make a recording error for example, and very useful to detect, because an incomplete jpeg file, make a crash for a lot of application)

We use this patch of imghdr :

--------------------------------------
def test_jpeg(h, f):
    """JPEG data in JFIF or Exif format"""
    if not h.startswith(b'\xff\xd8'):#Test empty files, and incorrect start of file
        return None
    else:
        if f:#if we test a file, test end of jpeg
            f.seek(-2,2)
            if f.read(2).endswith(b'\xff\xd9'):
                return 'jpeg'
        else:#if we just test the header, consider this is a valid jpeg and not test end of file
            return 'jpeg'
-------------------------------------
History
Date User Action Args
2014-06-21 18:44:22mvignalisetrecipients: + mvignali, jcea, vstinner, ezio.melotti, r.david.murray, intgr, Claudiu.Popa, kovid, joril
2014-06-21 18:44:22mvignalisetmessageid: <1403376262.23.0.0860237004994.issue16512@psf.upfronthosting.co.za>
2014-06-21 18:44:22mvignalilinkissue16512 messages
2014-06-21 18:44:21mvignalicreate