diff options
author | Dominik Stadler <centic@apache.org> | 2021-12-05 17:34:44 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2021-12-05 17:34:44 +0000 |
commit | 1e9efb5562517c657293e49d57654f3bd55fc3a5 (patch) | |
tree | b039afd19a2c03d2187f48a67107647219733ca1 /poi-scratchpad | |
parent | f0e7cc0881856ba25a965504e68a70f7dd9046b3 (diff) | |
download | poi-1e9efb5562517c657293e49d57654f3bd55fc3a5.tar.gz poi-1e9efb5562517c657293e49d57654f3bd55fc3a5.zip |
Fix issues found when fuzzing Apache POI via Jazzer
Add some null-checks and report more meaningful exceptions
This provides a bit more information than simple NullPointExceptions
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895600 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-scratchpad')
4 files changed, 44 insertions, 13 deletions
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideMaster.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideMaster.java index dbd5079118..513c8319c3 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideMaster.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideMaster.java @@ -143,14 +143,23 @@ public final class HSLFSlideMaster extends HSLFMasterSheet { assert (_txmaster == null); _txmaster = new TxMasterStyleAtom[9]; + if (getSlideShow() == null || getSlideShow().getDocumentRecord() == null || + getSlideShow().getDocumentRecord().getEnvironment() == null) { + throw new IllegalStateException("Did not find a TxMasterStyleAtom in the current slide show"); + } + TxMasterStyleAtom txdoc = getSlideShow().getDocumentRecord().getEnvironment().getTxMasterStyleAtom(); + if (txdoc == null) { + throw new IllegalStateException("Did not find a TxMasterStyleAtom in the current slide show"); + } + _txmaster[txdoc.getTextType()] = txdoc; TxMasterStyleAtom[] txrec = ((MainMaster)getSheetContainer()).getTxMasterStyleAtoms(); - for (int i = 0; i < txrec.length; i++) { - int txType = txrec[i].getTextType(); + for (TxMasterStyleAtom txMasterStyleAtom : txrec) { + int txType = txMasterStyleAtom.getTextType(); if (txType < _txmaster.length && _txmaster[txType] == null) { - _txmaster[txType] = txrec[i]; + _txmaster[txType] = txMasterStyleAtom; } } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java index 466f780336..f7c7d4fa7e 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java @@ -276,7 +276,9 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh // Find the Document, and interesting things in it if (record.getRecordType() == RecordTypes.Document.typeID) { _documentRecord = (Document) record; - _fonts = _documentRecord.getEnvironment().getFontCollection(); + if (_documentRecord.getEnvironment() != null) { + _fonts = _documentRecord.getEnvironment().getFontCollection(); + } } } /*else { // No record at this number @@ -414,6 +416,10 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh int slideId = spa.getSlideIdentifier(); slideIdToNotes.put(slideId, idx); + if (notesRecord.getNotesAtom() == null) { + throw new IllegalStateException("Could not read NotesAtom from the NotesRecord for " + idx); + } + HSLFNotes hn = new HSLFNotes(notesRecord); hn.setSlideShow(this); _notes.add(hn); @@ -436,11 +442,16 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh // Ensure it really is a slide record if (!(r instanceof Slide)) { - LOG.atError().log("A Slide SlideAtomSet at {} said its record was at refID {}, but that was actually a {}", box(idx),box(spa.getRefID()),r); + LOG.atError().log("A Slide SlideAtomSet at {} said its record was at refID {}, but that was actually a {}", + box(idx), box(spa.getRefID()), r); continue; } Slide slide = (Slide)r; + if (slide.getSlideAtom() == null) { + LOG.atError().log("SlideAtomSet at {} at refID {} is null", box(idx), box(spa.getRefID())); + continue; + } // Do we have a notes for this? HSLFNotes notes = null; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java index 6d35f371da..09dfffbcb9 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java @@ -310,10 +310,17 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { private void initRecordOffsets(byte[] docstream, int usrOffset, NavigableMap<Integer, Record> recordMap, Map<Integer, Integer> offset2id) { while (usrOffset != 0) { UserEditAtom usr = (UserEditAtom) Record.buildRecordAtOffset(docstream, usrOffset); + if (usr == null) { + throw new CorruptPowerPointFileException("Powerpoint document contains no user edit atom"); + } + recordMap.put(usrOffset, usr); int psrOffset = usr.getPersistPointersOffset(); PersistPtrHolder ptr = (PersistPtrHolder) Record.buildRecordAtOffset(docstream, psrOffset); + if (ptr == null) { + throw new CorruptPowerPointFileException("Powerpoint document is missing a PersistPtrHolder at " + psrOffset); + } recordMap.put(psrOffset, ptr); for (Map.Entry<Integer, Integer> entry : ptr.getSlideLocationsLookup().entrySet()) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java index 318b0ffded..98218e2d23 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java @@ -1322,14 +1322,18 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText * For a given PPDrawing, grab all the TextRuns */ public static List<List<HSLFTextParagraph>> findTextParagraphs(PPDrawing ppdrawing, HSLFSheet sheet) { - List<List<HSLFTextParagraph>> runsV = new ArrayList<>(); - for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) { - List<HSLFTextParagraph> p = findTextParagraphs(wrapper, sheet); - if (p != null) { - runsV.add(p); - } - } - return runsV; + if (ppdrawing == null) { + throw new IllegalArgumentException("Did not receive a valid drawing for sheet " + sheet._getSheetNumber()); + } + + List<List<HSLFTextParagraph>> runsV = new ArrayList<>(); + for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) { + List<HSLFTextParagraph> p = findTextParagraphs(wrapper, sheet); + if (p != null) { + runsV.add(p); + } + } + return runsV; } /** |