You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2017/12/09 11:44:19 UTC
svn commit: r1817599 - in /poi: site/src/documentation/content/xdocs/
trunk/src/scratchpad/src/org/apache/poi/hslf/record/
trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/
trunk/test-data/slideshow/
Author: kiwiwings
Date: Sat Dec 9 11:44:19 2017
New Revision: 1817599
URL: http://svn.apache.org/viewvc?rev=1817599&view=rev
Log:
#61881 - handle invalid font names
Added:
poi/trunk/test-data/slideshow/bug61881.ppt (with props)
Modified:
poi/site/src/documentation/content/xdocs/status.xml
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java
Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1817599&r1=1817598&r2=1817599&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Sat Dec 9 11:44:19 2017
@@ -67,6 +67,7 @@
<summary-item>Removal of deprecated classes and methods that were marked for removal in v3.18</summary-item>
</summary>
<actions>
+ <action dev="PD" type="fix" fixes-bug="61881" module="HSLF">Regression in ppt parsing: typeface can't be null or empty</action>
<action dev="PD" type="add" fixes-bug="github-68" module="XDDF,XSLF,XSSF,XWPF">Share chart data implementation between XSLFChart, XSSFChart and XWPFChart through XDDF</action>
<action dev="PD" type="fix" fixes-bug="61809" module="HPSF">Infinite loop in SectionIDMap.get() and .put()</action>
<action dev="PD" type="add" fixes-bug="60887" module="XSSF">Surface XSSF Header/Footer Attributes</action>
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java?rev=1817599&r1=1817598&r2=1817599&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java Sat Dec 9 11:44:19 2017
@@ -86,15 +86,39 @@ public final class FontEntityAtom extend
* @return font name
*/
public String getFontName(){
- int maxLen = Math.min(_recdata.length,64);
- for(int i = 0; i < maxLen; i+=2){
+ final int maxLen = Math.min(_recdata.length,64);
+ for(int i = 0; i+1 < maxLen; i+=2){
//loop until find null-terminated end of the font name
- if(_recdata[i] == 0 && _recdata[i + 1] == 0) {
+ if(_recdata[i] == 0 && _recdata[i + 1] == 0 && !isFontNamePremature0terminated(i)) {
return StringUtil.getFromUnicodeLE(_recdata, 0, i/2);
}
}
return null;
}
+
+ /**
+ * #61881: there seem to be programs out there, which write the 0-termination also
+ * at the beginning of the string. Check if the next two bytes contain a valid ascii char
+ * and correct the _recdata with a '?' char
+ */
+ private boolean isFontNamePremature0terminated(final int index) {
+ if (index > 0) {
+ // for now we only check the first char
+ return false;
+ }
+
+ if (_recdata.length < index+4) {
+ return false;
+ }
+
+ final int cp = LittleEndian.getShort(_recdata, index+2);
+ if (!Character.isJavaIdentifierPart(cp)) {
+ return false;
+ }
+
+ _recdata[index] = '?';
+ return true;
+ }
/**
* Set the name of the font.
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java?rev=1817599&r1=1817598&r2=1817599&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java Sat Dec 9 11:44:19 2017
@@ -23,9 +23,12 @@ import static org.junit.Assert.assertNul
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.usermodel.HSLFFontInfo;
import org.apache.poi.hslf.usermodel.HSLFFontInfoPredefined;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.poifs.storage.RawDataUtil;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -34,6 +37,8 @@ import org.junit.Test;
* Tests {@code FontCollection} and {@code FontEntityAtom} records
*/
public final class TestFontCollection {
+ private static final POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
+
// From a real file
private static byte[] data;
@@ -87,4 +92,13 @@ public final class TestFontCollection {
byte[] recdata = out.toByteArray();
assertArrayEquals(recdata, data);
}
+
+ @Test
+ public void bug61881() throws IOException {
+ try (InputStream is = _slTests.openResourceAsStream("bug61881.ppt")) {
+ try (HSLFSlideShow ppt = new HSLFSlideShow(is)) {
+ assertEquals("?imes New Roman",ppt.getFont(3).getTypeface());
+ }
+ }
+ }
}
Added: poi/trunk/test-data/slideshow/bug61881.ppt
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/bug61881.ppt?rev=1817599&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/slideshow/bug61881.ppt
------------------------------------------------------------------------------
svn:mime-type = application/vnd.ms-powerpoint
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org