Merge branch 'main' into dev

This commit is contained in:
DRC
2023-01-16 17:02:01 -06:00
5 changed files with 70 additions and 22 deletions

View File

@@ -857,6 +857,43 @@ final class TJUnitTest {
if (tjd != null) tjd.close();
}
static void overflowTest() throws Exception {
/* Ensure that the various buffer size methods don't overflow */
int size = 0;
boolean exception = false;
try {
exception = false;
size = TJ.bufSize(26755, 26755, TJ.SAMP_444);
} catch (Exception e) { exception = true; }
if (!exception || size != 0)
throw new Exception("TJ.bufSize() overflow");
try {
exception = false;
size = TJ.bufSizeYUV(37838, 1, 37838, TJ.SAMP_444);
} catch (Exception e) { exception = true; }
if (!exception || size != 0)
throw new Exception("TJ.bufSizeYUV() overflow");
try {
exception = false;
size = TJ.bufSizeYUV(37837, 3, 37837, TJ.SAMP_444);
} catch (Exception e) { exception = true; }
if (!exception || size != 0)
throw new Exception("TJ.bufSizeYUV() overflow");
try {
exception = false;
size = TJ.bufSizeYUV(37837, -1, 37837, TJ.SAMP_444);
} catch (Exception e) { exception = true; }
if (!exception || size != 0)
throw new Exception("TJ.bufSizeYUV() overflow");
try {
exception = false;
size = TJ.planeSizeYUV(0, 65536, 0, 65536, TJ.SAMP_444);
} catch (Exception e) { exception = true; }
if (!exception || size != 0)
throw new Exception("TJ.planeSizeYUV() overflow");
}
static void bufSizeTest() throws Exception {
int w, h, i, subsamp, flags = 0, quality = 100, numSamp = TJ.NUMSAMP;
byte[] srcBuf, dstBuf = null;
@@ -942,6 +979,7 @@ final class TJUnitTest {
throw new Exception("Lossless JPEG and YUV encoding/decoding are incompatible.");
if (doYUV)
FORMATS_4BYTE[4] = -1;
overflowTest();
doTest(35, 39, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_444,
testName);
doTest(39, 41, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_444,

View File

@@ -166,9 +166,10 @@
</dd>
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress(int,%20int,%20int,%20int)">decompress(int, int, int, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>
<div class="block">Decompress the JPEG source image or decode the YUV source image associated
with this decompressor instance and return a <code>BufferedImage</code>
instance containing the packed-pixel decompressed/decoded image.</div>
<div class="block">Decompress the JPEG source image or decode the planar YUV source image
associated with this decompressor instance and return a
<code>BufferedImage</code> instance containing the packed-pixel
decompressed/decoded image.</div>
</dd>
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html#decompressToYUV(org.libjpegturbo.turbojpeg.YUVImage,%20int)">decompressToYUV(YUVImage, int)</a></span> - Method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</a></dt>
<dd>

View File

@@ -271,9 +271,10 @@ implements java.io.Closeable</pre>
int&nbsp;desiredHeight,
int&nbsp;bufferedImageType,
int&nbsp;flags)</code>
<div class="block">Decompress the JPEG source image or decode the YUV source image associated
with this decompressor instance and return a <code>BufferedImage</code>
instance containing the packed-pixel decompressed/decoded image.</div>
<div class="block">Decompress the JPEG source image or decode the planar YUV source image
associated with this decompressor instance and return a
<code>BufferedImage</code> instance containing the packed-pixel
decompressed/decoded image.</div>
</td>
</tr>
<tr class="rowColor">
@@ -1093,9 +1094,10 @@ implements java.io.Closeable</pre>
int&nbsp;bufferedImageType,
int&nbsp;flags)
throws <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the JPEG source image or decode the YUV source image associated
with this decompressor instance and return a <code>BufferedImage</code>
instance containing the packed-pixel decompressed/decoded image.</div>
<div class="block">Decompress the JPEG source image or decode the planar YUV source image
associated with this decompressor instance and return a
<code>BufferedImage</code> instance containing the packed-pixel
decompressed/decoded image.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>desiredWidth</code> - see
<a href="../../../org/libjpegturbo/turbojpeg/TJDecompressor.html#decompress(byte[],%20int,%20int,%20int,%20int,%20int,%20int,%20int)"><code>decompress(byte[], int, int, int, int, int, int, int)</code></a> for
description</dd><dd><code>desiredHeight</code> - see

View File

@@ -803,9 +803,10 @@ public class TJDecompressor implements Closeable {
}
/**
* Decompress the JPEG source image or decode the YUV source image associated
* with this decompressor instance and return a <code>BufferedImage</code>
* instance containing the packed-pixel decompressed/decoded image.
* Decompress the JPEG source image or decode the planar YUV source image
* associated with this decompressor instance and return a
* <code>BufferedImage</code> instance containing the packed-pixel
* decompressed/decoded image.
*
* @param desiredWidth see
* {@link #decompress(byte[], int, int, int, int, int, int, int)} for

View File

@@ -132,24 +132,28 @@ bailout:
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSize
(JNIEnv *env, jclass cls, jint width, jint height, jint jpegSubsamp)
{
jint retval = (jint)tjBufSize(width, height, jpegSubsamp);
unsigned long retval = tjBufSize(width, height, jpegSubsamp);
if (retval == -1) THROW_ARG(tjGetErrorStr());
if (retval == (unsigned long)-1) THROW_ARG(tjGetErrorStr());
if (retval > (unsigned long)((unsigned int)-1))
THROW_ARG("Image is too large");
bailout:
return retval;
return (jint)retval;
}
/* TurboJPEG 1.4.x: TJ::bufSizeYUV() */
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII
(JNIEnv *env, jclass cls, jint width, jint align, jint height, jint subsamp)
{
jint retval = (jint)tjBufSizeYUV2(width, align, height, subsamp);
unsigned long retval = tjBufSizeYUV2(width, align, height, subsamp);
if (retval == -1) THROW_ARG(tjGetErrorStr());
if (retval == (unsigned long)-1) THROW_ARG(tjGetErrorStr());
if (retval > (unsigned long)((unsigned int)-1))
THROW_ARG("Image is too large");
bailout:
return retval;
return (jint)retval;
}
/* TurboJPEG 1.4.x: TJ::planeSizeYUV() */
@@ -157,13 +161,15 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeSizeYUV__IIIII
(JNIEnv *env, jclass cls, jint componentID, jint width, jint stride,
jint height, jint subsamp)
{
jint retval = (jint)tjPlaneSizeYUV(componentID, width, stride, height,
subsamp);
unsigned long retval = tjPlaneSizeYUV(componentID, width, stride, height,
subsamp);
if (retval == -1) THROW_ARG(tjGetErrorStr());
if (retval == (unsigned long)-1) THROW_ARG(tjGetErrorStr());
if (retval > (unsigned long)((unsigned int)-1))
THROW_ARG("Image is too large");
bailout:
return retval;
return (jint)retval;
}
/* TurboJPEG 1.4.x: TJ::planeWidth() */