浏览代码

Bug 55732 - PPT can't open, fails with "Couldn't instantiate .... StyleTextProp9Atom : java.lang.ArrayIndexOutOfBoundsException: 56"

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1569984 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_11_BETA1
Andreas Beeker 10 年前
父节点
当前提交
146eadef69

+ 36
- 29
src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java 查看文件



/** /**
* The atom record that specifies additional text formatting. * The atom record that specifies additional text formatting.
*
* @author Alex Nikiforov [mailto:anikif@gmail.com]
*/ */
public final class StyleTextProp9Atom extends RecordAtom { public final class StyleTextProp9Atom extends RecordAtom {
private final TextPFException9[] autoNumberSchemes;
private final TextPFException9[] autoNumberSchemes;
/** Record header. */ /** Record header. */
private byte[] header; private byte[] header;
/** Record data. */ /** Record data. */
*/ */
protected StyleTextProp9Atom(byte[] source, int start, int len) { protected StyleTextProp9Atom(byte[] source, int start, int len) {
// Get the header. // Get the header.
final List<TextPFException9> schemes = new LinkedList<TextPFException9>();
final List<TextPFException9> schemes = new LinkedList<TextPFException9>();
header = new byte[8]; header = new byte[8];
System.arraycopy(source,start, header,0,8); System.arraycopy(source,start, header,0,8);
this.version = LittleEndian.getShort(header, 0); this.version = LittleEndian.getShort(header, 0);
data = new byte[len-8]; data = new byte[len-8];
System.arraycopy(source, start+8, data, 0, len-8); System.arraycopy(source, start+8, data, 0, len-8);
for (int i = 0; i < data.length; ) { for (int i = 0; i < data.length; ) {
final TextPFException9 item = new TextPFException9(data, i);
schemes.add(item);
i += item.getRecordLength();
//int textCfException9 = LittleEndian.getInt(data, i );
//TODO analyze textCfException when have some test data
i += 4;
int textSiException = LittleEndian.getInt(data, i );
i += + 4;//TextCFException9 + SIException
if (0 != (textSiException & 0x40)) {
i += 2; //skip fBidi
}
if (i >= data.length) {
break;
}
final TextPFException9 item = new TextPFException9(data, i);
schemes.add(item);
i += item.getRecordLength();
if (i >= data.length) {
break;
}
int textCfException9 = LittleEndian.getInt(data, i );
i += 4;
//TODO analyze textCfException when have some test data
if (i >= data.length) {
break;
}
int textSiException = LittleEndian.getInt(data, i );
i += 4;//TextCFException9 + SIException
if (0 != (textSiException & 0x40)) {
i += 2; //skip fBidi
}
if (i >= data.length) {
break;
}
} }
this.autoNumberSchemes = (TextPFException9[]) schemes.toArray(new TextPFException9[schemes.size()]); this.autoNumberSchemes = (TextPFException9[]) schemes.toArray(new TextPFException9[schemes.size()]);
} }


/**
/**
* Gets the record type. * Gets the record type.
* @return the record type. * @return the record type.
*/ */
public long getRecordType() { return this.recordId; } public long getRecordType() { return this.recordId; }


public short getVersion() { public short getVersion() {
return version;
}
return version;
}


public int getLength() {
return length;
}
public TextPFException9[] getAutoNumberTypes() {
return this.autoNumberSchemes;
}
public int getLength() {
return length;
}
public TextPFException9[] getAutoNumberTypes() {
return this.autoNumberSchemes;
}


/**
/**
* Write the contents of the record back, so it can be written * Write the contents of the record back, so it can be written
* to disk * to disk
* *
// Update the size (header bytes 5-8) // Update the size (header bytes 5-8)
LittleEndian.putInt(header, 4, data.length); LittleEndian.putInt(header, 4, data.length);
} }
}
}

+ 18
- 0
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java 查看文件

import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import org.apache.poi.hslf.exceptions.OldPowerPointFormatException; import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
import org.apache.poi.hslf.model.Background; import org.apache.poi.hslf.model.Background;
import org.apache.poi.hslf.model.Fill; import org.apache.poi.hslf.model.Fill;
import org.apache.poi.hslf.model.HeadersFooters;
import org.apache.poi.hslf.model.MasterSheet; import org.apache.poi.hslf.model.MasterSheet;
import org.apache.poi.hslf.model.Notes; import org.apache.poi.hslf.model.Notes;
import org.apache.poi.hslf.model.Picture; import org.apache.poi.hslf.model.Picture;
} }
} }


@Test
public void bug55732() throws Exception {
File file = _slTests.getFile("bug55732.ppt");
HSLFSlideShow ss = new HSLFSlideShow(file.getAbsolutePath());
SlideShow _show = new SlideShow(ss);
Slide[] _slides = _show.getSlides();

/* Iterate over slides and extract text */
for( Slide slide : _slides ) {
HeadersFooters hf = slide.getHeadersFooters();
boolean visible = hf.isHeaderVisible(); // exception happens here
}
assertTrue("No Exceptions while reading headers", true);
}
} }

二进制
test-data/slideshow/bug55732.ppt 查看文件


正在加载...
取消
保存