Skip to content

Commit

Permalink
Bug 66425: Avoid exceptions found via poi-fuzz
Browse files Browse the repository at this point in the history
We try to avoid throwing NullPointerException, ClassCastExceptions 
and StackOverflowException, but it was possible to trigger them

Also improve some exception messages

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=62698
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=62606
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=62685

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912707 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
centic9 committed Oct 3, 2023
1 parent 105966c commit 360c05d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public ShapeType getShapeType(){
@Override
public Rectangle2D getAnchor(){
CTTransform2D xfrm = ((CTGraphicalObjectFrame)getXmlObject()).getXfrm();
if (xfrm == null) {
throw new IllegalArgumentException("Could not retrieve an Xfrm from the XML object");
}

CTPoint2D off = xfrm.getOff();
double x = Units.toPoints(POIXMLUnits.parseLength(off.xgetX()));
double y = Units.toPoints(POIXMLUnits.parseLength(off.xgetY()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ public boolean isBold() {
return super.isBold();
} else {
final CTTextCharacterProperties rPr = super.getRPr(false);
if (rPr.isSetB()) {
if (rPr != null && rPr.isSetB()) {
// If this run has bold set locally, then it overrides table cell style.
return rPr.getB();
} else {
Expand All @@ -784,7 +784,7 @@ public boolean isItalic() {
return super.isItalic();
} else {
final CTTextCharacterProperties rPr = super.getRPr(false);
if (rPr.isSetI()) {
if (rPr != null && rPr.isSetI()) {
// If this run has italic set locally, then it overrides table cell style.
return rPr.getI();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ public SXSSFSheet(SXSSFWorkbook workbook, XSSFSheet xSheet) throws IOException {
setRandomAccessWindowSize(_workbook.getRandomAccessWindowSize());
try {
_autoSizeColumnTracker = new AutoSizeColumnTracker(this);
} catch (UnsatisfiedLinkError | InternalError e) {
LOG.atWarn().log("Failed to create AutoSizeColumnTracker, possibly due to fonts not being installed in your OS", e);
} catch (UnsatisfiedLinkError | NoClassDefFoundError | InternalError |
// thrown when no fonts are available in the workbook
IndexOutOfBoundsException e) {
LOG.atWarn()
.withThrowable(e)
.log("Failed to create AutoSizeColumnTracker, possibly due to fonts not being installed in your OS");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
public class PointerContainingStream extends Stream { // TODO - instantiable superclass
private static final Logger LOG = LogManager.getLogger(PointerContainingStream.class);

private static final int MAX_CHILDREN_NESTING = 1000;
private static final int MAX_CHILDREN_NESTING = 500;

private final Pointer[] childPointers;
private Stream[] childStreams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected static String getString(byte[] data, CodepageRecord codepage) {
try {
return CodePageUtil.getStringFromCodePage(data, cp);
} catch (UnsupportedEncodingException uee) {
throw new IllegalArgumentException("Unsupported codepage requested", uee);
throw new IllegalArgumentException("Unsupported codepage requested: " + cp, uee);
}
}

Expand Down

0 comments on commit 360c05d

Please sign in to comment.