From e706f37170789876a930461924fbe84c34c5dfa8 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Tue, 8 Aug 2023 08:48:13 +0000 Subject: [PATCH] Bug 66425: Avoid a ClassCastException found via oss-fuzz We try to avoid throwing ClassCastException, but it was possible to trigger one here with a specially crafted input-file Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61276 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1911536 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/record/TextObjectRecord.java | 3 +++ .../poi/hssf/dev/BaseTestIteratingXLS.java | 2 ++ ...nimized-POIHSSFFuzzer-6322470200934400.xls | Bin 0 -> 3347 bytes test-data/spreadsheet/stress.xls | Bin 61952 -> 62464 bytes 4 files changed, 5 insertions(+) create mode 100644 test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-6322470200934400.xls diff --git a/poi/src/main/java/org/apache/poi/hssf/record/TextObjectRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/TextObjectRecord.java index c399bd64f9..17bcce71e7 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/TextObjectRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/TextObjectRecord.java @@ -127,6 +127,9 @@ public final class TextObjectRecord extends ContinuableRecord { throw new RecordFormatException("Read " + ptgs.length + " tokens but expected exactly 1"); } + if (!(ptgs[0] instanceof OperandPtg)) { + throw new IllegalArgumentException("Had unexpected type of ptg at index 0: " + ptgs[0].getClass()); + } _linkRefPtg = (OperandPtg) ptgs[0]; _unknownPostFormulaByte = in.remaining() > 0 ? in.readByte() : null; } else { diff --git a/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java b/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java index 45de3c2155..26627b5a9b 100644 --- a/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java +++ b/poi/src/test/java/org/apache/poi/hssf/dev/BaseTestIteratingXLS.java @@ -86,6 +86,8 @@ public abstract class BaseTestIteratingXLS { excludes.put("61300.xls", RecordFormatException.class); // BIFF 5 excludes.put("64130.xls", OldExcelFormatException.class); + // fuzzed binaries + excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6322470200934400.xls", RuntimeException.class); return excludes; } diff --git a/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-6322470200934400.xls b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-6322470200934400.xls new file mode 100644 index 0000000000000000000000000000000000000000..40f4ecaeaeadd45d5ef5c54040394ad23bed0a11 GIT binary patch literal 3347 zcmeH~y-or_5Xa}>`0@)uKm~=c7ijK9ziStK`ovH*Dv zdI5EgCW8b!W4vA~c^#_%A@3%y;WN?wan%RL&)3h5wG)8{@HO`VKL~&x(3>XeL)i}o zKoDRHPzZ#<5Qu;%h=E}+0!Bd`B)}LL2T70u5|{v!Kn8pqT_$fG84upoY`M$grWUH68(O#<^Tj%%?@^XEwQ*!ycs82Dbzlk64;}m;6benqc-JhU}$yvaOKEMfoTsoSX)rKKZ zMVO&ExIC?c$qN?TaJ9Oc1|wvRHjft{2m$#YHHu&K~D^F3pytiYam@`32S zl(FS&8n+94lVX%Ecz%>+SxGC({Ip(4iU~|25~SW%3^vr0Vvw$QzUAhsQ&~%^L=`4! z6I6ZNNuAc;2t0!7Tmg)yi!tX4;9LQ|?}+wVIL6Kupqk69uK=pGSj>8ff6iFg%+$rY JQvU=(`wKrfZsPy| literal 0 HcmV?d00001 diff --git a/test-data/spreadsheet/stress.xls b/test-data/spreadsheet/stress.xls index 70847a482cd28fd42546e61516cf7bfa49290244..cf344f0b847ecad437b31bced212587486dde191 100644 GIT binary patch delta 1233 zcmZvbZA@EL7{`D2ww1QDg|V_B!no?DAB0f>fhi%dO@b(8ikkwPGAJX9we6(SrXXF6 zx-Ux9V|;0AWSSUbmSx$EF)oXVnt*Qu@q>nCF-B*c$)bMI51S63TUeE7oA&oS&pGG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