aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2023-12-30 11:11:36 +0000
committerDominik Stadler <centic@apache.org>2023-12-30 11:11:36 +0000
commit28811d26dfd4aab9560683ace083f61ce1834b63 (patch)
tree139a26d4b7bb4d09a3bf5ea5d13534d84c079113
parent8e3b60f63d21458c59b9bf10dde10dcc2fa928b0 (diff)
downloadpoi-28811d26dfd4aab9560683ace083f61ce1834b63.tar.gz
poi-28811d26dfd4aab9560683ace083f61ce1834b63.zip
Bug 66425: Avoid exceptions found via poi-fuzz
Prevent ClassCastException Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=63375 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1914990 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java6
1 files changed, 5 insertions, 1 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java b/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java
index 75c343b33f..9c0b081c19 100644
--- a/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java
+++ b/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java
@@ -44,7 +44,7 @@ import org.apache.poi.ss.formula.eval.NotImplementedException;
@SuppressWarnings("serial")
public class FractionFormat extends Format {
private static final Logger LOGGER = LogManager.getLogger(FractionFormat.class);
- private static final Pattern DENOM_FORMAT_PATTERN = Pattern.compile("(?:(#+)|(\\d+))");
+ private static final Pattern DENOM_FORMAT_PATTERN = Pattern.compile("(#+)|(\\d+)");
//this was chosen to match the earlier limitation of max denom power
//it can be expanded to get closer to Excel's calculations
@@ -189,6 +189,10 @@ public class FractionFormat extends Format {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
+ if (!(obj instanceof Number)) {
+ throw new IllegalArgumentException("Cannot format object of " + obj.getClass() + " to number: " + obj);
+ }
+
return toAppendTo.append(format((Number)obj));
}