diff options
author | Dominik Stadler <centic@apache.org> | 2023-12-30 11:11:36 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2023-12-30 11:11:36 +0000 |
commit | 28811d26dfd4aab9560683ace083f61ce1834b63 (patch) | |
tree | 139a26d4b7bb4d09a3bf5ea5d13534d84c079113 | |
parent | 8e3b60f63d21458c59b9bf10dde10dcc2fa928b0 (diff) | |
download | poi-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.java | 6 |
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)); } |