Did you check if libjpeg is able to report such errors?