]> granicus.if.org Git - libjpeg-turbo/commitdiff
Java: Fix NullPointerException in YUVImage
authorDRC <information@libjpeg-turbo.org>
Mon, 14 Aug 2017 15:54:27 +0000 (10:54 -0500)
committerDRC <information@libjpeg-turbo.org>
Mon, 14 Aug 2017 16:46:26 +0000 (11:46 -0500)
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
java/org/libjpegturbo/turbojpeg/YUVImage.java

index 2aaa50c14846896a6335df781d230cc5243005a0..3d5987f2b997c65519c7146fd1eaf7034fcbd3e9 100644 (file)
@@ -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
 =====
 
index 1a05e62f68492c21e02c3c3283b4a127ef45a826..d123e3724ff90c674ee236ed80b0f06bd1c21ab4 100644 (file)
@@ -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)