You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2026/02/14 20:28:15 UTC
(poi) 03/06: Avoid NPE with malformed anchors in slideshow files
This is an automated email from the ASF dual-hosted git repository.
centic pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
commit 55c1608a2d0e236c270bf8f833f4719f6996dc7e
Author: Dominik Stadler <do...@gmx.at>
AuthorDate: Sat Feb 14 17:15:14 2026 +0100
Avoid NPE with malformed anchors in slideshow files
---
.../apache/poi/hslf/usermodel/HSLFGroupShape.java | 18 +++++++++++-------
.../62d2ecd89aeb715b07072d4f8a8734f4dbeb5c10.ppt | Bin 0 -> 224256 bytes
test-data/spreadsheet/stress.xls | Bin 78848 -> 78848 bytes
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFGroupShape.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
index 1754e67d2b..66edf97706 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
@@ -78,7 +78,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
public void setAnchor(Rectangle2D anchor) {
EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
boolean isInitialized = !(clientAnchor.getDx1() == 0 && clientAnchor.getRow1() == 0);
-
+
if (isInitialized) {
moveAndScale(anchor);
} else {
@@ -113,7 +113,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
protected void setExteriorAnchor(Rectangle2D anchor) {
EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
-
+
//hack. internal variable EscherClientAnchorRecord.shortRecord can be
//initialized only in fillFields(). We need to set shortRecord=false;
byte[] header = new byte[16];
@@ -131,7 +131,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
// TODO: does this make sense?
setInteriorAnchor(anchor);
}
-
+
/**
* Create a new ShapeGroup and create an instance of <code>EscherSpgrContainer</code> which represents a group of shapes
*/
@@ -186,7 +186,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
double scaleY = (anchorSrc.getHeight() == 0) ? 0 : anchorDest.getHeight() / anchorSrc.getHeight();
setExteriorAnchor(anchorDest);
-
+
for (HSLFShape shape : getShapes()) {
Rectangle2D chanchor = shape.getAnchor();
double x = anchorDest.getX()+(chanchor.getX()-anchorSrc.getX())*scaleX;
@@ -204,12 +204,16 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
* @return the anchor of this shape group
*/
@Override
- public Rectangle2D getAnchor(){
+ public Rectangle2D getAnchor() {
EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
int x1,y1,x2,y2;
- if(clientAnchor == null){
+ if(clientAnchor == null) {
LOG.atInfo().log("EscherClientAnchorRecord was not found for shape group. Searching for EscherChildAnchorRecord.");
EscherChildAnchorRecord rec = getEscherChild(EscherChildAnchorRecord.RECORD_ID);
+ if (rec == null) {
+ throw new IllegalStateException("Cannot get anchor, neither had an EscherClientAnchorRecord nor an EscherChildAnchorRecord");
+ }
+
x1 = rec.getDx1();
y1 = rec.getDy1();
x2 = rec.getDx2();
@@ -293,7 +297,7 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
isFirst = false;
continue;
}
-
+
if(r instanceof EscherContainerRecord) {
// Create the Shape for it
EscherContainerRecord container = (EscherContainerRecord)r;
diff --git a/test-data/slideshow/62d2ecd89aeb715b07072d4f8a8734f4dbeb5c10.ppt b/test-data/slideshow/62d2ecd89aeb715b07072d4f8a8734f4dbeb5c10.ppt
new file mode 100644
index 0000000000..05256ad4a5
Binary files /dev/null and b/test-data/slideshow/62d2ecd89aeb715b07072d4f8a8734f4dbeb5c10.ppt differ
diff --git a/test-data/spreadsheet/stress.xls b/test-data/spreadsheet/stress.xls
index 9b4388c582..a6db95bc78 100644
Binary files a/test-data/spreadsheet/stress.xls and b/test-data/spreadsheet/stress.xls differ
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org