From 32120054c224d1911ebe33dc664c0f730a7782b2 Mon Sep 17 00:00:00 2001 From: DRC Date: Mon, 14 Aug 2017 10:54:27 -0500 Subject: [PATCH] Java: Fix NullPointerException in YUVImage planes == null is a valid argument to setBuf() if alloc == true, so we need to make sure that planes is non-null before validating its length. We also need to allocate one dimension of the planes array if it's null. Fixes #168 --- ChangeLog.md | 10 ++++++++++ java/org/libjpegturbo/turbojpeg/YUVImage.java | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 2aaa50c..3d5987f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,13 @@ +1.5.3 +===== + +### Significant changes relative to 1.5.2: + +1. Fixed a NullPointerException in the TurboJPEG Java wrapper that occurred +when using the YUVImage constructor that creates an instance backed by separate +image planes and allocates memory for the image planes. + + 1.5.2 ===== diff --git a/java/org/libjpegturbo/turbojpeg/YUVImage.java b/java/org/libjpegturbo/turbojpeg/YUVImage.java index 1a05e62..d123e37 100644 --- a/java/org/libjpegturbo/turbojpeg/YUVImage.java +++ b/java/org/libjpegturbo/turbojpeg/YUVImage.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2014 D. R. Commander. All Rights Reserved. + * Copyright (C)2014, 2017 D. R. Commander. All Rights Reserved. * Copyright (C)2015 Viktor Szathmáry. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without @@ -220,10 +220,13 @@ public class YUVImage { throw new IllegalArgumentException("Invalid argument in YUVImage::setBuf()"); int nc = (subsamp == TJ.SAMP_GRAY ? 1 : 3); - if (planes.length != nc || (offsets != null && offsets.length != nc) || + if ((planes != null && planes.length != nc) || + (offsets != null && offsets.length != nc) || (strides != null && strides.length != nc)) throw new IllegalArgumentException("YUVImage::setBuf(): planes, offsets, or strides array is the wrong size"); + if (planes == null) + planes = new byte[nc][]; if (offsets == null) offsets = new int[nc]; if (strides == null) -- 2.40.0