Fix broken JPEG file detection

Fixes #2063