fix #19, only need check first two bytes for jpg
(cherry picked from commit 0b2b3577a1f63849ea9d43bd67d0485b3210d6f1)