From 9d7d2f26e028c3560c6649b9196f403c99975955 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 19 Aug 2022 09:02:15 +0000 Subject: [PATCH] more int narrowing git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903560 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hemf/record/emfplus/HemfPlusBrush.java | 8 ++++---- .../poi/hemf/record/emfplus/HemfPlusObject.java | 4 ++-- .../poi/hemf/record/emfplus/HemfPlusPen.java | 6 +++--- .../org/apache/poi/hslf/dev/SlideShowDumper.java | 15 +++------------ .../hslf/record/HSLFEscherClientDataRecord.java | 2 +- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java index ec0ac8e465..f2fc063258 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java @@ -709,7 +709,7 @@ public class HemfPlusBrush { // that appears at the center point of the brush. The color of the brush changes gradually from the // boundary color to the center color as it moves from the boundary to the center point. centerColor = readARGB(leis.readInt()); - int size = 3*LittleEndianConsts.INT_SIZE; + long size = 3*LittleEndianConsts.INT_SIZE; if (wrapMode == null) { return size; @@ -785,7 +785,7 @@ public class HemfPlusBrush { size += 3*LittleEndianConsts.INT_SIZE; } - return size; + return Math.toIntExact(size); } @Override @@ -846,7 +846,7 @@ public class HemfPlusBrush { // across a shape, when the image is smaller than the area being filled. wrapMode = EmfPlusWrapMode.valueOf(leis.readInt()); - int size = 2*LittleEndianConsts.INT_SIZE; + long size = 2*LittleEndianConsts.INT_SIZE; if (TRANSFORM.isSet(dataFlags)) { size += readXForm(leis, (brushTransform = new AffineTransform())); @@ -856,7 +856,7 @@ public class HemfPlusBrush { size += (image = new EmfPlusImage()).init(leis, dataSize-size, EmfPlusObjectType.IMAGE, 0); } - return size; + return Math.toIntExact(size); } @Override diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java index 1e04c5524e..2553102d11 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java @@ -174,7 +174,7 @@ public class HemfPlusObject { EmfPlusObjectType objectType = getObjectType(); assert (objectType != null); - int size = 0; + long size = 0; totalObjectSize = 0; int dataSize2 = (int) dataSize; @@ -192,7 +192,7 @@ public class HemfPlusObject { objectData = objectType.constructor.get(); size += objectData.init(leis, dataSize2, objectType, flags); - return size; + return Math.toIntExact(size); } @Override diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java index cd00d453cc..42dd6e44e6 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusPen.java @@ -533,7 +533,7 @@ public class HemfPlusPen { @SuppressWarnings("unused") private long initCustomCap(Consumer setter, LittleEndianInputStream leis) throws IOException { int CustomStartCapSize = leis.readInt(); - int size = LittleEndianConsts.INT_SIZE; + long size = LittleEndianConsts.INT_SIZE; EmfPlusGraphicsVersion version = new EmfPlusGraphicsVersion(); size += version.init(leis); @@ -547,13 +547,13 @@ public class HemfPlusPen { setter.accept(cap); - return size; + return Math.toIntExact(size); } @Override public void applyObject(HemfGraphics ctx, List continuedObjectData) { final HemfDrawProperties prop = ctx.getProperties(); - // TOOD: + // TODO: // - set width according unit type // - provide logic for different start and end cap // - provide standard caps like diamond diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowDumper.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowDumper.java index 084b15b9c1..d4d6094743 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowDumper.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SlideShowDumper.java @@ -281,19 +281,10 @@ public final class SlideShowDumper { if (recordLen == 8 && atomLen > 8) { // Assume it has children, rather than being corrupted walkEscherDDF((indent + 3), pos + 8, (int) atomLen); - - // Wind on our length + our header - pos += atomLen; - pos += 8; - len -= atomLen; - len -= 8; - } else { - // No children, wind on our real length - pos += atomLen; - pos += 8; - len -= atomLen; - len -= 8; } + // Wind on our length + our header + pos = Math.toIntExact(pos + atomLen) + 8; + len = Math.toIntExact(len - atomLen) - 8; // Move on to the next one, if we're not at the end yet if (len >= 8) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java index 328efb1b29..14751254d6 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java @@ -113,7 +113,7 @@ public class HSLFEscherClientDataRecord extends EscherClientDataRecord { _childRecords.add(r); } long rlen = LittleEndian.getUInt(remainingData,offset+4); - offset += 8 + rlen; + offset = Math.toIntExact(offset + 8 + rlen); } } -- 2.39.5