classification
Title: imghdr doesn't recognize some jpeg formats
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: 4simple-org, Claudiu.Popa, ezio.melotti, intgr, jcea, joril, kovid, mvignali, r.david.murray, vstinner, xiang.zhang
Priority: normal Keywords: patch

Created on 2016-11-02 20:06 by 4simple-org, last changed 2016-11-10 23:13 by 4simple-org.

Files
File name Uploaded Description Edit
1.jpg 4simple-org, 2016-11-02 20:06
2.jpg 4simple-org, 2016-11-02 20:10
imghdr27.patch 4simple-org, 2016-11-02 21:02 patch for python 2.7
imghdr35.patch 4simple-org, 2016-11-02 21:05 patch for python 3.X
imghdr_py27.py 4simple-org, 2016-11-02 21:07 Working imghdr lib for python 2.7.X
imghdr_py3.py 4simple-org, 2016-11-02 21:08 Working imghdr lib for python 3.X
imghdr_py3.patch 4simple-org, 2016-11-10 21:32 New patch for imghdr bug, including unittets. This patch works on python 3.x review
python1.jpg 4simple-org, 2016-11-10 21:35 Image used in the unit-tests of previous patch.
imghdr_py27.patch 4simple-org, 2016-11-10 23:13 New patch for imghdr bug, including unittets. This patch works on python 2.7 review
Messages (14)
msg279940 - (view) Author: Raul (4simple-org) Date: 2016-11-02 20:06
Some valid JPEG images are not detected by the imghdr lib.
msg279941 - (view) Author: Raul (4simple-org) Date: 2016-11-02 20:10
Other valid jpeg image not detected.
msg279946 - (view) Author: Raul (4simple-org) Date: 2016-11-02 21:02
patch for python 2.7
msg279947 - (view) Author: Raul (4simple-org) Date: 2016-11-02 21:03
patch for python 3.X
msg279948 - (view) Author: Raul (4simple-org) Date: 2016-11-02 21:05
patch for python 3.X
msg279949 - (view) Author: Raul (4simple-org) Date: 2016-11-02 21:07
Working imghdr lib for python 2.7.X
msg279950 - (view) Author: Raul (4simple-org) Date: 2016-11-02 21:08
Working imghdr lib for python 3.X
msg279952 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-11-02 21:40
There seem to be unrelated changes in your patches, and we'll want tests as well before committing.  See also issue 16512 and the issues linked from it.  (I haven't reviewed to see if there is any overlap.)
msg279963 - (view) Author: Kovid Goyal (kovid) Date: 2016-11-03 04:06
FYI, the uptodate version of imghdr I maintain is here:
https://github.com/kovidgoyal/calibre/blob/master/src/calibre/utils/imghdr.py

It uses memoryview for performance and can also also read image sizes from file headers for jpeg, png, gif and jpeg2000. Note that is is only tested on python 2.7

I'm afraid I dont have the time to shepherd it through your review process, but feel free to take code from it if you want to. It is licensed GPLv3 but I am willing to re-license to another license if needed, as I am the sole contributor.
msg279965 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-11-03 05:02
There is also #27121 reporting similar problem.
msg280544 - (view) Author: Raul (4simple-org) Date: 2016-11-10 21:32
New patch for imghdr bug, including unittets. This patch works on python 3.x
msg280545 - (view) Author: Raul (4simple-org) Date: 2016-11-10 21:35
Image used in the unit-tests of previous patch.
Add it under Lib/test/imghdrdata/python1.jpg
msg280546 - (view) Author: Raul (4simple-org) Date: 2016-11-10 21:37
The issue16512 don't solve the problem, note how the patch it provide fails to detect all the valid JPEG images attached in this issue.
msg280550 - (view) Author: Raul (4simple-org) Date: 2016-11-10 23:13
New patch for imghdr bug, including unittets. This patch works on python 2.7
History
Date User Action Args
2016-11-10 23:13:374simple-orgsetfiles: + imghdr_py27.patch

messages: + msg280550
2016-11-10 21:37:414simple-orgsetmessages: + msg280546
2016-11-10 21:35:274simple-orgsetfiles: + python1.jpg

messages: + msg280545
2016-11-10 21:32:264simple-orgsetfiles: + imghdr_py3.patch

messages: + msg280544
2016-11-03 05:02:25xiang.zhangsetnosy: + xiang.zhang

messages: + msg279965
versions: - Python 3.3, Python 3.4
2016-11-03 04:06:09kovidsetmessages: + msg279963
2016-11-02 21:40:45r.david.murraysetmessages: + msg279952
2016-11-02 21:08:264simple-orgsetfiles: + imghdr_py3.py

messages: + msg279950
2016-11-02 21:07:434simple-orgsetfiles: + imghdr_py27.py

messages: + msg279949
2016-11-02 21:05:114simple-orgsetfiles: + imghdr35.patch

messages: + msg279948
2016-11-02 21:03:534simple-orgsetfiles: - imghdr35.py
2016-11-02 21:03:114simple-orgsetfiles: + imghdr35.py

messages: + msg279947
2016-11-02 21:02:374simple-orgsetfiles: + imghdr27.patch
keywords: + patch
messages: + msg279946
2016-11-02 20:10:144simple-orgsetfiles: + 2.jpg

messages: + msg279941
2016-11-02 20:06:184simple-orgcreate