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:
@@ -263,7 +263,7 @@ int main(int argc, char **argv)
|
||||
if (!strcasecmp(inFormat, "jpg")) {
|
||||
/* Input image is a JPEG image. Decompress and/or transform it. */
|
||||
long size;
|
||||
int inSubsamp, inColorspace;
|
||||
int inSubsamp, inColorspace, inFlags;
|
||||
int doTransform = (xform.op != TJXOP_NONE || xform.options != 0 ||
|
||||
xform.customFilter != NULL);
|
||||
unsigned long jpegSize;
|
||||
@@ -304,10 +304,13 @@ int main(int argc, char **argv)
|
||||
THROW_TJ("initializing decompressor");
|
||||
}
|
||||
|
||||
if (tjDecompressHeader3(tjInstance, jpegBuf, jpegSize, &width, &height,
|
||||
&inSubsamp, &inColorspace) < 0)
|
||||
if (tjDecompressHeader4(tjInstance, jpegBuf, jpegSize, &width, &height,
|
||||
&inSubsamp, &inColorspace, &inFlags) < 0)
|
||||
THROW_TJ("reading JPEG header");
|
||||
|
||||
if (inFlags & TJFLAG_LOSSLESS)
|
||||
scalingFactor.num = scalingFactor.denom = 1;
|
||||
|
||||
printf("%s Image: %d x %d pixels, %s subsampling, %s colorspace\n",
|
||||
(doTransform ? "Transformed" : "Input"), width, height,
|
||||
subsampName[inSubsamp], colorspaceName[inColorspace]);
|
||||
|
||||
Reference in New Issue
Block a user