You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/11/13 14:09:37 UTC
(commons-imaging) 01/02: Avoid java.lang.NullPointerException in org.apache.commons.imaging.formats.pcx.PcxWriter.writeImage().
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
commit a3447665d0cbfc00a3ad0aa98379227909c201d5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Nov 13 09:09:09 2023 -0500
Avoid java.lang.NullPointerException in
org.apache.commons.imaging.formats.pcx.PcxWriter.writeImage().
---
src/changes/changes.xml | 3 +++
src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java | 4 +++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 89af2774..5887aef6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -72,6 +72,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" due-to="Gary Gregory">
Do not implement Serializable in ColorCountComparator and RgbComparator.
</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">
+ Avoid java.lang.NullPointerException in org.apache.commons.imaging.formats.pcx.PcxWriter.writeImage().
+ </action>
<!-- ADD -->
<action issue="IMAGING-352" dev="ggregory" type="add" due-to="Jeroen van der Vegt, Gary Gregory">
[PngWriter] Allow custom PaletteFactory #294.
diff --git a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java
index 8cc7a0fd..fbe2ee25 100644
--- a/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java
+++ b/src/main/java/org/apache/commons/imaging/formats/pcx/PcxWriter.java
@@ -126,9 +126,11 @@ final class PcxWriter {
}
final byte[] palette16 = new byte[16 * 3];
+ // TODO What's the right thing to do here for a null palette?
+ final int paletteLen = palette != null ? palette.length() : 0;
for (int i = 0; i < 16; i++) {
int rgb;
- if (i < palette.length()) {
+ if (i < paletteLen) {
rgb = palette.getEntry(i);
} else {
rgb = 0;