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 @@ -865,7 +865,14 @@ public ListAutoNumber getBulletAutoNumberScheme() {
ParagraphPropertyFetcher<ListAutoNumber> fetcher = new ParagraphPropertyFetcher<ListAutoNumber>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetBuAutoNum() && props.getBuAutoNum().getType() != null) {
setValue(ListAutoNumber.values()[props.getBuAutoNum().getType().intValue() - 1]);
int typeIdx = props.getBuAutoNum().getType().intValue() - 1;
ListAutoNumber[] values = ListAutoNumber.values();
if (typeIdx >= 0 && typeIdx < values.length) {
setValue(values[typeIdx]);
} else {
// Fallback handling: use the default format when the value is out of range
setValue(ListAutoNumber.ARABIC_PLAIN);
}
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Licensed to the Apache Software Foundation (ASF) under one or more

import static org.junit.jupiter.api.Assertions.*;

import org.openxmlformats.schemas.drawingml.x2006.main.STTextAutonumberScheme;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextAutonumberBullet;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextAutonumberScheme;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;

import java.awt.Color;
import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -224,4 +230,35 @@ void testXSSFTextParagraph2() throws IOException {
assertArrayEquals(run.getFontColorAsBytes(), run2.getFontColorAsBytes());
}
}

@Test
public void testBulletAutoNumberSchemeOutOfBounds() throws IOException{
try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFSheet sheet = wb.createSheet();
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 0, 0, 1, 1));

// Ensure the paragraph is created correctly
XSSFTextParagraph para = shape.addNewTextParagraph();

// 1. Obtain or create the underlying XML structure
CTTextParagraph ctPara = para.getXmlObject();
CTTextParagraphProperties pr = ctPara.isSetPPr() ? ctPara.getPPr() : ctPara.addNewPPr();

// 2. Force a level to avoid ParagraphPropertyFetcher errors
pr.setLvl(0);

// 3. Set an out-of-range autonumber type (e.g. 24)
CTTextAutonumberBullet bullet = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();
bullet.setType(STTextAutonumberScheme.Enum.forInt(24));

// 4. Execute the test
// If you haven't applied the fix, this line will throw AIOOBE
// If the fix is applied, this should return ARABIC_PLAIN
ListAutoNumber result = para.getBulletAutoNumberScheme();

assertNotNull(result, "Result should not be null");
assertEquals(ListAutoNumber.ARABIC_PLAIN, result, "Should fallback to ARABIC_PLAIN for unknown index");
}
}
}