You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by se...@apache.org on 2011/10/22 04:23:19 UTC
svn commit: r1187644 - in /poi/trunk/src/java/org/apache/poi/hpsf:
CodePageString.java UnicodeString.java
Author: sergey
Date: Sat Oct 22 02:23:19 2011
New Revision: 1187644
URL: http://svn.apache.org/viewvc?rev=1187644&view=rev
Log:
some files has strange property values... try to handle them.
Modified:
poi/trunk/src/java/org/apache/poi/hpsf/CodePageString.java
poi/trunk/src/java/org/apache/poi/hpsf/UnicodeString.java
Modified: poi/trunk/src/java/org/apache/poi/hpsf/CodePageString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/CodePageString.java?rev=1187644&r1=1187643&r2=1187644&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/CodePageString.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/CodePageString.java Sat Oct 22 02:23:19 2011
@@ -22,11 +22,16 @@ import java.io.UnsupportedEncodingExcept
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
@Internal
class CodePageString
{
+ private final static POILogger logger = POILogFactory
+ .getLogger( CodePageString.class );
+
private static String codepageToEncoding( final int codepage )
throws UnsupportedEncodingException
{
@@ -172,7 +177,23 @@ class CodePageString
result = new String( _value );
else
result = new String( _value, codepageToEncoding( codepage ) );
- return result.substring( 0, result.length() - 1 );
+ final int terminator = result.indexOf( '\0' );
+ if ( terminator == -1 )
+ {
+ logger.log(
+ POILogger.WARN,
+ "String terminator (\\0) for CodePageString property value not found."
+ + "Continue without trimming and hope for the best." );
+ return result;
+ }
+ if ( terminator != result.length() - 1 )
+ {
+ logger.log(
+ POILogger.WARN,
+ "String terminator (\\0) for CodePageString property value occured before the end of string. "
+ + "Trimming and hope for the best." );
+ }
+ return result.substring( 0, terminator );
}
int getSize()
Modified: poi/trunk/src/java/org/apache/poi/hpsf/UnicodeString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/UnicodeString.java?rev=1187644&r1=1187643&r2=1187644&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/UnicodeString.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/UnicodeString.java Sat Oct 22 02:23:19 2011
@@ -18,11 +18,17 @@ package org.apache.poi.hpsf;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
import org.apache.poi.util.StringUtil;
@Internal
class UnicodeString
{
+
+ private final static POILogger logger = POILogFactory
+ .getLogger( UnicodeString.class );
+
private byte[] _value;
UnicodeString( byte[] data, int offset )
@@ -59,7 +65,25 @@ class UnicodeString
if ( _value.length == 0 )
return null;
- return StringUtil.getFromUnicodeLE( _value, 0,
- ( _value.length - 2 ) >> 1 );
+ String result = StringUtil.getFromUnicodeLE( _value, 0,
+ _value.length >> 1 );
+
+ final int terminator = result.indexOf( '\0' );
+ if ( terminator == -1 )
+ {
+ logger.log(
+ POILogger.WARN,
+ "String terminator (\\0) for UnicodeString property value not found."
+ + "Continue without trimming and hope for the best." );
+ return result;
+ }
+ if ( terminator != result.length() - 1 )
+ {
+ logger.log(
+ POILogger.WARN,
+ "String terminator (\\0) for UnicodeString property value occured before the end of string. "
+ + "Trimming and hope for the best." );
+ }
+ return result.substring( 0, terminator );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org