Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public class TestAllFiles {
// invalid files
"spreadsheet/bug69769.xlsx",

// fuzz files
"slideshow/clusterfuzz-testcase-minimized-POIHSLFFuzzer-4630915954114560.ppt",

// NOTE: Expected failures should usually be added in file "poi-integration-exceptions.csv" instead
// of being listed here in order to also verify the expected exception details!
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public class XSLFDrawing {
// ignore them for now
if (o instanceof CTNonVisualDrawingProps) {
CTNonVisualDrawingProps p = (CTNonVisualDrawingProps)o;
sheet.registerShapeId((int)p.getId());
try {
sheet.registerShapeId(Math.toIntExact(p.getId()));
} catch (ArithmeticException e) {
throw new IllegalStateException("Int overflow with drawing id " + p.getId());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,12 @@ public boolean fetch(XSLFShape shape) {
CTShapeStyle style = getSpStyle();
if (style != null && style.getEffectRef() != null) {
// 1-based index of a shadow style within the style matrix
int idx = (int) style.getEffectRef().getIdx();
int idx;
try {
idx = Math.toIntExact(style.getEffectRef().getIdx());
} catch (ArithmeticException e) {
throw new IllegalStateException("Int overflow with effect ref id " + style.getEffectRef().getIdx());
}
if(idx != 0) {
CTStyleMatrix styleMatrix = getSheet().getTheme().getXmlObject().getThemeElements().getFmtScheme();
CTEffectStyleItem ef = styleMatrix.getEffectStyleLst().getEffectStyleArray(idx - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class XSLFTabStop implements TabStop {

/** position in EMUs */
public int getPosition() {
return (int)POIXMLUnits.parseLength(tabStop.xgetPos());
return Math.toIntExact(POIXMLUnits.parseLength(tabStop.xgetPos()));
}

/** position in EMUs */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ public CTTransform2D getCTTransform2D() {
}

public int getDx1() {
return (int)t2d.getOff().getX();
return Math.toIntExact((Long)t2d.getOff().getX());
}

public void setDx1(int dx1) {
t2d.getOff().setX(dx1);
}

public int getDy1() {
return (int)t2d.getOff().getY();
return Math.toIntExact((Long)t2d.getOff().getY());
}

public void setDy1(int dy1) {
t2d.getOff().setY(dy1);
}

public int getDy2() {
return (int)(getDy1() + t2d.getExt().getCy());
return Math.toIntExact(getDy1() + t2d.getExt().getCy());
}

public void setDy2(int dy2) {
t2d.getExt().setCy(dy2 - (long)getDy1());
}

public int getDx2() {
return (int)(getDx1() + t2d.getExt().getCx());
return Math.toIntExact(getDx1() + t2d.getExt().getCx());
}

public void setDx2(int dx2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void setRGB(byte[] rgb) {
*/
@Override
public int getTheme() {
return (int) ctColor.getTheme();
return Math.toIntExact(ctColor.getTheme());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
StylesTable styles = _sh.getWorkbook().getStylesSource();
CTDxf dxf = null;
if(styles._getDXfsSize() > 0 && _cfRule.isSetDxfId()){
int dxfId = (int)_cfRule.getDxfId();
int dxfId = Math.toIntExact(_cfRule.getDxfId());
dxf = styles.getDxfAt(dxfId);
}
if(create && dxf == null) {
Expand Down Expand Up @@ -349,7 +349,7 @@ public ExcelNumberFormat getNumberFormat() {
if(dxf == null || !dxf.isSetNumFmt()) return null;

CTNumFmt numFmt = dxf.getNumFmt();
return new ExcelNumberFormat((int) numFmt.getNumFmtId(), numFmt.getFormatCode());
return new ExcelNumberFormat(Math.toIntExact(numFmt.getNumFmtId()), numFmt.getFormatCode());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public void setLeftToRight(boolean ltr) {
}

public int getWidthMin() {
return (int)_databar.getMinLength();
return Math.toIntExact(_databar.getMinLength());
}
public void setWidthMin(int width) {
_databar.setMinLength(width);
}

public int getWidthMax() {
return (int)_databar.getMaxLength();
return Math.toIntExact(_databar.getMaxLength());
}
public void setWidthMax(int width) {
_databar.setMaxLength(width);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public XSSFDxfStyleProvider(CTDxf dxf, int stripeSize, IndexedColorMap colorMap)
font = dxf.isSetFont() ? new XSSFFontFormatting(dxf.getFont(), colorMap) : null;
if (dxf.isSetNumFmt()) {
CTNumFmt numFmt = dxf.getNumFmt();
number = new ExcelNumberFormat((int) numFmt.getNumFmtId(), numFmt.getFormatCode());
number = new ExcelNumberFormat(Math.toIntExact(numFmt.getNumFmtId()), numFmt.getFormatCode());
} else {
number = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public short getFontColorIndex(){

int idx = 0;
CTColor color = _font.getColorArray(0);
if(color.isSetIndexed()) idx = (int)color.getIndexed();
if(color.isSetIndexed()) idx = Math.toIntExact(color.getIndexed());
return (short)idx;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void setSheetIndex(int index) {
*/
@Override
public int getSheetIndex() {
return _ctName.isSetLocalSheetId() ? (int) _ctName.getLocalSheetId() : -1;
return _ctName.isSetLocalSheetId() ? Math.toIntExact(_ctName.getLocalSheetId()) : -1;
}

/**
Expand Down Expand Up @@ -283,7 +283,7 @@ public void setFunctionGroupId(int functionGroupId) {
* @return the function group index that defines the general category for the function
*/
public int getFunctionGroupId() {
return (int) _ctName.getFunctionGroupId();
return Math.toIntExact(_ctName.getFunctionGroupId());
}

/**
Expand All @@ -296,7 +296,7 @@ public int getFunctionGroupId() {
public String getSheetName() {
if (_ctName.isSetLocalSheetId()) {
// Given as explicit sheet id
int sheetId = (int)_ctName.getLocalSheetId();
int sheetId = Math.toIntExact(_ctName.getLocalSheetId());
return _workbook.getSheetName(sheetId);
}
String ref = getRefersToFormula();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static int optimiseFonts(XSSFWorkbook workbook) {
for (int i = 0; i < ctXfs.sizeOfXfArray(); i++) {
CTXf xf = ctXfs.getXfArray(i);
if (xf.isSetFontId()) {
int oldFontId = (int) xf.getFontId();
int oldFontId = Math.toIntExact(xf.getFontId());
int canonicalFontId = oldToCanonical.getOrDefault(oldFontId, oldFontId);
if (canonicalFontId != oldFontId) {
xf.setFontId(canonicalFontId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ private static void applyAttributes(CTRPrElt pr, CTTextCharacterProperties rPr)
CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();
clr.setVal(xlsColor.getRgb());
} else if (xlsColor.isSetIndexed()) {
HSSFColor indexed = HSSFColor.getIndexHash().get((int) xlsColor.getIndexed());
HSSFColor indexed = HSSFColor.getIndexHash().get(Math.toIntExact(xlsColor.getIndexed()));
if (indexed != null) {
byte[] rgb = new byte[3];
rgb[0] = (byte) indexed.getTriplet()[0];
Expand All @@ -1015,7 +1015,7 @@ public String getShapeName() {

@Override
public int getShapeId() {
return (int) ctShape.getNvSpPr().getCNvPr().getId();
return Math.toIntExact(ctShape.getNvSpPr().getCNvPr().getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public XSSFTableStyle(int index, CTDxfs dxfs, CTTableStyle tableStyle, IndexedCo
TableStyleType type = TableStyleType.valueOf(element.getType().toString());
DifferentialStyleProvider dstyle = null;
if (element.isSetDxfId()) {
int idx = (int) element.getDxfId();
int idx = Math.toIntExact(element.getDxfId());
CTDxf dxf;
dxf = dxfList.get(idx);
int stripeSize = 0;
if (element.isSetSize()) stripeSize = (int) element.getSize();
if (element.isSetSize()) stripeSize = Math.toIntExact(element.getSize());
if (dxf != null) dstyle = new XSSFDxfStyleProvider(dxf, stripeSize, colorMap);
}
elementMap.put(type, dstyle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ public XSSFSheet createSheet(String sheetname) {
outerloop:
while(true) {
for(XSSFSheet sh : sheets) {
sheetNumber = (int)Math.max(sh.sheet.getSheetId() + 1, sheetNumber);
sheetNumber = Math.toIntExact(Math.max(sh.sheet.getSheetId() + 1, sheetNumber));
}

// Bug 57165: We also need to check that the resulting file name is not already taken
Expand Down Expand Up @@ -1046,7 +1046,7 @@ public XSSFFont findFont(boolean bold, short color, short fontHeight, String nam
public int getActiveSheetIndex() {
//activeTab (Active Sheet Index) Specifies an unsignedInt
//that contains the index to the active sheet in this book view.
return (int)workbook.getBookViews().getWorkbookViewArray(0).getActiveTab();
return Math.toIntExact(workbook.getBookViews().getWorkbookViewArray(0).getActiveTab());
}

/**
Expand Down Expand Up @@ -2062,7 +2062,7 @@ public void setSheetVisibility(int sheetIx, SheetVisibility visibility) {
*/
protected void onDeleteFormula(XSSFCell cell){
if(calcChain != null) {
int sheetId = (int)cell.getSheet().sheet.getSheetId();
int sheetId = Math.toIntExact(cell.getSheet().sheet.getSheetId());
calcChain.removeItem(sheetId, cell.getReference());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void setColDefaultStyle(long index, int styleId) {
public int getColDefaultStyle(long index) {
final CTCol column = getColumn(index, false);
if (column != null) {
return (int) column.getStyle();
return Math.toIntExact(column.getStyle());
}
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public HemfRecordType getEmfRecordType() {
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long startIdx = leis.getReadIndex();
data = new EmfCommentDataIterator(leis, (int)recordSize, true).next();
data = new EmfCommentDataIterator(leis, Math.toIntExact(recordSize), true).next();
return leis.getReadIndex()-startIdx;
}

Expand Down Expand Up @@ -152,9 +152,10 @@ public Map<String, Supplier<?>> getGenericProperties() {
}

static void validateCommentType(final LittleEndianInputStream leis, HemfCommentRecordType commentType) {
int commentIdentifier = (int)leis.readUInt();
// comment identifiers are uint32 values used as bit-pattern identifiers, not numeric values
int commentIdentifier = (int) leis.readUInt();
if (commentIdentifier == HemfCommentRecordType.emfPublic.id) {
commentIdentifier = (int)leis.readUInt();
commentIdentifier = (int) leis.readUInt();
}
assert(commentIdentifier == commentType.id);
}
Expand Down Expand Up @@ -232,10 +233,10 @@ private EmfCommentData _next() {
// See the preceding table for descriptions of these record types.
// Valid comment identifier values are listed in the following table.
//
// If this field contains any other value, the comment record MUST be an EMR_COMMENT record
final int commentIdentifier = (int)leis.readUInt();
// comment identifiers are uint32 values used as bit-pattern identifiers, not numeric values
final int commentIdentifier = (int) leis.readUInt();
// A 32-bit unsigned integer that identifies the type of public comment record.
final int publicCommentIdentifier = (int)leis.readUInt();
final int publicCommentIdentifier = (int) leis.readUInt();

final boolean isEmfPublic = (commentIdentifier == HemfCommentRecordType.emfPublic.id);
leis.reset();
Expand All @@ -246,7 +247,7 @@ private EmfCommentData _next() {
final EmfCommentData record = commentType.constructor.get();

long readBytes = record.init(leis, dataSize);
final int skipBytes = (int)(recordSize-4-readBytes);
final int skipBytes = Math.toIntExact(recordSize-4-readBytes);
assert (skipBytes >= 0);
leis.skipFully(skipBytes);

Expand Down Expand Up @@ -331,7 +332,7 @@ public long init(final LittleEndianInputStream leis, final long dataSize)
throws IOException {
final long startIdx = leis.getReadIndex();
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfPlus);
new HemfPlusRecordIterator(leis, (int)dataSize-LittleEndianConsts.INT_SIZE).forEachRemaining(records::add);
new HemfPlusRecordIterator(leis, Math.toIntExact(dataSize)-LittleEndianConsts.INT_SIZE).forEachRemaining(records::add);
return leis.getReadIndex()-startIdx;
}

Expand Down Expand Up @@ -385,7 +386,7 @@ public long init(final LittleEndianInputStream leis, final long dataSize) throws
HemfDraw.readRectL(leis, bounds);

// The number of Unicode characters in the optional description string that follows.
int nDescription = (int)leis.readUInt();
int nDescription = Math.toIntExact(leis.readUInt());

byte[] buf = IOUtils.safelyAllocate(nDescription * 2L, HwmfPicture.getMaxRecordLength());
leis.readFully(buf);
Expand Down Expand Up @@ -448,7 +449,7 @@ public long init(final LittleEndianInputStream leis, final long dataSize) throws
HemfDraw.readRectL(leis, bounds);

// A 32-bit unsigned integer that specifies the number of graphics formats contained in this record.
int countFormats = (int)leis.readUInt();
int countFormats = Math.toIntExact(leis.readUInt());
for (int i=0; i<countFormats; i++) {
EmfCommentDataFormat fmt = new EmfCommentDataFormat();
long readBytes = fmt.init(leis, dataSize, startIdx);
Expand Down Expand Up @@ -602,7 +603,7 @@ public long init(final LittleEndianInputStream leis, final long dataSize) throws

// A 32-bit unsigned integer that specifies the size, in bytes, of the
// WMF metafile in the WinMetafile field.
int winMetafileSize = (int)leis.readUInt();
int winMetafileSize = Math.toIntExact(leis.readUInt());

wmfData = IOUtils.safelyAllocate(winMetafileSize, HwmfPicture.getMaxRecordLength());
// some emf comments are truncated, so we don't use readFully here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public long init(LittleEndianInputStream leis, long recordSize, long recordId) t
*
* Any extra points MUST be ignored.
*/
final int count = (int)leis.readUInt();
final int count = Math.toIntExact(leis.readUInt());
final int points = Math.min(count, 16384);
size += LittleEndianConsts.INT_SIZE;

Expand Down Expand Up @@ -275,7 +275,7 @@ public long init(LittleEndianInputStream leis, long recordSize, long recordId) t
long size = readRectL(leis, bounds);

// see PolyBezier about limits
final int count = (int)leis.readUInt();
final int count = Math.toIntExact(leis.readUInt());
final int points = Math.min(count, 16384);
size += LittleEndianConsts.INT_SIZE;

Expand Down Expand Up @@ -506,7 +506,7 @@ public long init(LittleEndianInputStream leis, long recordSize, long recordId) t

// An array of 32-bit unsigned integers that specifies the point count for each polygon.
IOUtils.safelyAllocateCheck(numberOfPolygons, MAX_NUMBER_OF_POLYGONS);
long[] polygonPointCount = new long[(int)numberOfPolygons];
long[] polygonPointCount = new long[Math.toIntExact(numberOfPolygons)];

size += numberOfPolygons * LittleEndianConsts.INT_SIZE;

Expand All @@ -518,7 +518,7 @@ public long init(LittleEndianInputStream leis, long recordSize, long recordId) t
for (long nPoints : polygonPointCount) {
// An array of WMF PointL objects that specifies the points for all polygons in logical units.
// The number of points is specified by the Count field value.
Path2D poly = new Path2D.Double(Path2D.WIND_EVEN_ODD, (int)nPoints);
Path2D poly = new Path2D.Double(Path2D.WIND_EVEN_ODD, Math.toIntExact(nPoints));
for (int i=0; i<nPoints; i++) {
size += readPoint(leis, pnt);
if (i == 0) {
Expand Down Expand Up @@ -827,8 +827,8 @@ public long init(LittleEndianInputStream leis, long recordSize, long recordId) t
long size = readRectL(leis, bounds);

// A 32-bit unsigned integer that defines the x-coordinate of the point.
int width = (int)leis.readUInt();
int height = (int)leis.readUInt();
int width = Math.toIntExact(leis.readUInt());
int height = Math.toIntExact(leis.readUInt());
corners.setSize(width, height);

return size + 2*LittleEndianConsts.INT_SIZE;
Expand Down Expand Up @@ -945,7 +945,7 @@ protected long readPoint(LittleEndianInputStream leis, Point2D point) {
@Override
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
long size = readRectL(leis, bounds);
int count = (int)leis.readUInt();
int count = Math.toIntExact(leis.readUInt());
size += LittleEndianConsts.INT_SIZE;
Point2D[] points = new Point2D[count];
for (int i=0; i<count; i++) {
Expand Down
Loading