From d44fc54f94cf5888e760a7256fb99b7e96cd926c Mon Sep 17 00:00:00 2001 From: DRC Date: Wed, 21 Aug 2024 15:00:58 -0400 Subject: [PATCH] Java: Unset srcBuf12/16 with BufferedImage/YUV src Due to an oversight in the multi-precision feature, TJCompressor.srcBuf12 and TJCompressor.srcBuf16 were not set to null in TJCompressor.setSourceImage(YUVImage) or TJCompressor.setSourceImage(BufferedImage, ...). Thus, if an application set a 12-bit or 16-bit packed-pixel buffer as the source image then set a BufferedImage with integer pixels as the source image, TJCompress.compress() would compress from the 12-bit or 16-bit packed-pixel buffer instead of the BufferedImage. The odds of an application actually doing that are very slim, however. --- java/org/libjpegturbo/turbojpeg/TJCompressor.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/java/org/libjpegturbo/turbojpeg/TJCompressor.java b/java/org/libjpegturbo/turbojpeg/TJCompressor.java index e47a2c9f..b18cb07d 100644 --- a/java/org/libjpegturbo/turbojpeg/TJCompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJCompressor.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2011-2015, 2018, 2020, 2022-2023 D. R. Commander. + * Copyright (C)2011-2015, 2018, 2020, 2022-2024 D. R. Commander. * All Rights Reserved. * Copyright (C)2015 Viktor Szathmáry. All Rights Reserved. * @@ -335,6 +335,8 @@ public class TJCompressor implements Closeable { DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); srcBufInt = db.getData(); srcBuf8 = null; + srcBuf12 = null; + srcBuf16 = null; } else { ComponentSampleModel sm = (ComponentSampleModel)srcImage.getSampleModel(); @@ -344,6 +346,8 @@ public class TJCompressor implements Closeable { srcPitch = sm.getScanlineStride(); DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); srcBuf8 = db.getData(); + srcBuf12 = null; + srcBuf16 = null; srcBufInt = null; } srcYUVImage = null; @@ -364,6 +368,8 @@ public class TJCompressor implements Closeable { srcYUVImage = srcImage; set(TJ.PARAM_SUBSAMP, srcImage.getSubsamp()); srcBuf8 = null; + srcBuf12 = null; + srcBuf16 = null; srcBufInt = null; }