TurboJPEG: Add lossless JPEG detection capability

Add a new TurboJPEG C API function (tjDecompressHeader4()) and Java API
method (TJDecompressor.getFlags()) that return the bitwise OR of any
flags that are relevant to the JPEG image being decompressed (currently
TJFLAG_PROGRESSIVE, TJFLAG_ARITHMETIC, TJFLAG_LOSSLESS, and their Java
equivalents.)  This allows a calling program to determine whether the
image being decompressed is a lossless JPEG image, which means that the
decompression scaling feature will not be available and that a
full-sized destination buffer should be allocated.

More specifically, this fixes a buffer overrun in TJBench, TJExample,
and the decompress* fuzz targets that occurred when attempting (in vain)
to decompress a lossless JPEG image with decompression scaling enabled.
This commit is contained in:
DRC
2022-11-21 20:57:39 -06:00
parent b85b028d2b
commit 98ff1fd103
32 changed files with 481 additions and 283 deletions

View File

@@ -1201,14 +1201,20 @@ DLLEXPORT tjhandle tjInitDecompress(void);
* image (see @ref TJCS "JPEG colorspaces".) If <tt>jpegBuf</tt>
* points to a tables-only datastream, then <tt>jpegColorspace</tt> is ignored.
*
* @param jpegFlags pointer to an integer variable that will receive the
* bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT "flags", such as
* #TJFLAG_PROGRESSIVE and #TJFLAG_LOSSLESS, that describe the JPEG image. If
* <tt>jpegBuf</tt> points to a tables-only datastream, then <tt>jpegFlags</tt>
* is ignored.
*
* @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
* and #tjGetErrorCode().)
*/
DLLEXPORT int tjDecompressHeader3(tjhandle handle,
DLLEXPORT int tjDecompressHeader4(tjhandle handle,
const unsigned char *jpegBuf,
unsigned long jpegSize, int *width,
int *height, int *jpegSubsamp,
int *jpegColorspace);
int *jpegColorspace, int *jpegFlags);
/**
@@ -1783,6 +1789,12 @@ DLLEXPORT int tjDecompressHeader2(tjhandle handle, unsigned char *jpegBuf,
unsigned long jpegSize, int *width,
int *height, int *jpegSubsamp);
DLLEXPORT int tjDecompressHeader3(tjhandle handle,
const unsigned char *jpegBuf,
unsigned long jpegSize, int *width,
int *height, int *jpegSubsamp,
int *jpegColorspace);
DLLEXPORT int tjDecompress(tjhandle handle, unsigned char *jpegBuf,
unsigned long jpegSize, unsigned char *dstBuf,
int width, int pitch, int height, int pixelSize,