ITK: Crash when use ImageFileReader read jpeg
Description
If compile with release version. When I use ImageFileReader read some broke jpeg image, it’s crash in Update function. I expected throw an exception.
But success in Debug.
Steps to Reproduce
Build With Release. https://gist.github.com/Hconk/5b1bed75ebb3c62757277a1367d61edb
Expected behavior
If image broke, expect throw an exception.
Actual behavior
Crash at update.


Reproducibility
Release Version.
Versions
c4960ee19c
Environment
- CMake: 3.21.1
- OS: Centos 7.3 / Windows 10
- ITK Version: 5.2.1 / master branch
- compile: gcc10.2 / gcc 4.8 / vs2017
Additional Information
Test data. Google Drive

About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (13 by maintainers)
Commits related to this issue
- BUG: segfault in JPEG IO on opening corrupted file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: segfault in JPEG IO on opening corrupted file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: fixed undefined behaviour with corrupted JPEG file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928 — committed to InsightSoftwareConsortium/ITK by issakomi 3 years ago
- BUG: PNG IO fails on corrupt file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928#issuecomment-991665972 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: PNG IO fails on corrupt file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928#issuecomment-991665972 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: PNG IO fails on corrupt file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928#issuecomment-991665972 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: PNG IO fails on corrupt file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928#issuecomment-991665972 — committed to issakomi/ITK by issakomi 3 years ago
- BUG: PNG IO fails on corrupt file S. https://github.com/InsightSoftwareConsortium/ITK/issues/2928#issuecomment-991665972 — committed to InsightSoftwareConsortium/ITK by issakomi 3 years ago
@dzenanz @issakomi I found some specially constructed png image also cause crash. When I use
PNGImageIOread it ,will got some libpng error infomationlibpng error: PNG unsigned integer out of rangethen crash. I think it’s need throw exception. Although it is not generated in a real scene, may also need to be fixed. (Maybe need open a new issue.)Example test data: https://drive.google.com/file/d/1wRMTQlz31lwccha9hdPb-uTwNXD77nZv/view?usp=sharing image sha256: f82d996c02975eecbdf0823bad5047124d3d146a0fb8804e377c35838ed264b8 Good image:
Broken png image hex:
The difference between the two pictures is at the 0x21st byte.
@issakomi Thanks, I validate your patch code, It’s work for me, This problem has bothered me for a long time.
Probably i have done a temporary fixed… The error happens in jpeg_destroy_decompress(&cinfo); I have re-written several times the Read function to find it out and tested additionally with version 4.12 with system JPEG (also crashed, BTW). So finally i looked inside Gimp code (Gimp doesn’t fail on the file). The minimal solution is to add
if (setjmp (jerr.setjmp_buffer))block at the beginning of the while loopand quit: before jpeg_destroy_decompress at the end of Read function, to skip jpeg_finish_decompress call in case of an error.
@Hconk Maybe you could validate?
P.S. Please don’t write me that “goto” is bad. It is not the final solution, it is minimal working for now.