Skip to content

Commit dec7995

Browse files
committed
Catch libjpeg errors in tjDecompressToYUV2()
Even though tjDecompressToYUV2() is mostly just a wrapper for tjDecompressToYUVPlanes(), tjDecompressToYUV2() still calls jpeg_read_header(), so it needs to properly set up the libjpeg error handler prior to making this call. Otherwise, under very esoteric (and arguably incorrect) use cases, a program can call tjDecompressToYUV2() without first checking the JPEG header using tjDecompressHeader3(), and if the header is corrupt, tjDecompressToYUV2() will abort without triggering an error. Fixes flutter#72
1 parent 2628c56 commit dec7995

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ included a similar fix for ASCII PPM/PGM files. Note that these issues were
1919
not security bugs, since they were confined to the cjpeg program and did not
2020
affect any of the libjpeg-turbo libraries.
2121

22+
4. Fixed an issue whereby attempting to decompress a JPEG file with a corrupt
23+
header using the `tjDecompressToYUV2()` function would cause the function to
24+
abort without returning an error. This only occurred if `tjDecompressToYUV2()`
25+
was called prior to calling `tjDecompressHeader3()`, or if the return value
26+
from `tjDecompressHeader3()` was ignored (both cases represent incorrect usage
27+
of the TurboJPEG API.)
28+
2229

2330
1.4.90 (1.5 beta1)
2431
==================

turbojpeg.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,12 @@ DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle,
18921892
|| !isPow2(pad) || height<0)
18931893
_throw("tjDecompressToYUV2(): Invalid argument");
18941894

1895+
if(setjmp(this->jerr.setjmp_buffer))
1896+
{
1897+
/* If we get here, the JPEG code has signaled an error. */
1898+
return -1;
1899+
}
1900+
18951901
jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
18961902
jpeg_read_header(dinfo, TRUE);
18971903
jpegSubsamp=getSubsamp(dinfo);

0 commit comments

Comments
 (0)