Skip to content

PR: Improve handling of truncated/incomplete and corrupt JPEG images #2471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 15, 2020

Conversation

andfoy
Copy link
Contributor

@andfoy andfoy commented Jul 14, 2020

This PR adds a set of tests to check that JPEG loading functions do not hang when supplying truncated/corrupt images. Now torchvision will raise an exception whenever an incomplete image is loaded.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for fixing this @andfoy !

// No more data. Probably an incomplete image; Raise exception.
torch_jpeg_error_ptr myerr = (torch_jpeg_error_ptr)cinfo->err;
strcpy(jpegLastErrorMsg, "Image is incomplete or truncated");
longjmp(myerr->setjmp_buffer, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

For future reference, here is how TensorFlow implements this function. I'm not sure if there are benefits for one over the other, but it's good for the record.

@fmassa fmassa merged commit 03b1d38 into pytorch:master Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants