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
This commit is contained in:
10
ChangeLog.md
10
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
|
||||
=====
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user