Martin Mirchev created PDFBOX-6332:
--------------------------------------
Summary: ArrayIndexOutOfBoundsException in PDFunctionType3.eval()
when /Bounds has too many entries for /Functions
Key: PDFBOX-6332
URL: https://issues.apache.org/jira/browse/PDFBOX-6332
Project: PDFBox
Issue Type: Bug
Components: Rendering
Affects Versions: 4.0.0, 3.0.8 PDFBox
Reporter: Martin Mirchev
Attachments: f3-extra-bounds.pdf, f3-no-functions.pdf, f3-ok.pdf
A type 3 (stitching) function with k functions should have k-1 /Bounds values.
{{PDFunctionType3.eval()}} builds its partitions from /Bounds alone, so when
/Bounds has k or more entries, or /Functions is empty, an input in one of the
extra partitions indexes past {{functionsArray}}. The exception escapes
{{PDFRenderer.renderImage()}}:
{code}
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
at
org.apache.pdfbox.pdmodel.common.function.PDFunctionType3.eval(PDFunctionType3.java:101)
{code}
Attached: {{f3-extra-bounds.pdf}} (an axial shading whose function has 2
functions and /Bounds [0.3 0.6]) and {{f3-no-functions.pdf}} (/Functions []),
which both throw; {{f3-ok.pdf}} (2 functions, /Bounds [0.5]) renders. Each
result was the same in 3 runs.
A possible change; with it, both files render (the shading code handles the
{{IOException}}) and {{f3-ok.pdf}} is unchanged:
{code}
---
a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType3.java
+++
b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunctionType3.java
@@ -85,6 +85,11 @@
boundsValues = getBounds().toFloatArray();
}
int boundsSize = boundsValues.length;
+ if (boundsSize >= functionsArray.length)
+ {
+ throw new IOException("Type 3 function has " + boundsSize + "
bounds for "
+ + functionsArray.length + " functions");
+ }
// create a combined array containing the domain and the bounds
values
// domain.min, bounds[0], bounds[1], ...., bounds[boundsSize-1],
domain.max
float[] partitionValues = new float[boundsSize+2];
{code}
This issue was found by an LLM-assisted tool and verified manually.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]