You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/05/20 17:42:16 UTC
svn commit: r658285 - in /poi/trunk/src: documentation/content/xdocs/
java/org/apache/poi/poifs/storage/ testcases/org/apache/poi/poifs/filesystem/
Author: nick
Date: Tue May 20 08:42:16 2008
New Revision: 658285
URL: http://svn.apache.org/viewvc?rev=658285&view=rev
Log:
Fix bug 44898 - Correctly handle short last blocks in POIFS
Modified:
poi/trunk/src/documentation/content/xdocs/changes.xml
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java
poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlockList.java
poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=658285&r1=658284&r2=658285&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Tue May 20 08:42:16 2008
@@ -37,7 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.1-final" date="2008-06-??">
- <action dev="POI-DEVELOPERS" type="add"><!-- to keep XML validator quiet --></action>
+ <action dev="POI-DEVELOPERS" type="fix">44898 - Correctly handle short last blocks in POIFS</action>
</release>
<release version="3.1-beta2" date="2008-05-26">
<action dev="POI-DEVELOPERS" type="fix">44306 - fixed reading/writing of AttrPtg(type=choose) and method toFormulaString() for CHOOSE formulas</action>
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=658285&r1=658284&r2=658285&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue May 20 08:42:16 2008
@@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1-final" date="2008-06-??">
+ <action dev="POI-DEVELOPERS" type="fix">44898 - Correctly handle short last blocks in POIFS</action>
</release>
<release version="3.1-beta2" date="2008-05-26">
<action dev="POI-DEVELOPERS" type="fix">44306 - fixed reading/writing of AttrPtg(type=choose) and method toFormulaString() for CHOOSE formulas</action>
Modified: poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java?rev=658285&r1=658284&r2=658285&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlock.java Tue May 20 08:42:16 2008
@@ -37,6 +37,7 @@
{
private byte[] _data;
private boolean _eof;
+ private boolean _hasData;
private static POILogger log = POILogFactory.getLogger(RawDataBlock.class);
/**
@@ -66,6 +67,7 @@
throws IOException {
_data = new byte[ blockSize ];
int count = IOUtils.readFully(stream, _data);
+ _hasData = (count > 0);
if (count == -1) {
_eof = true;
@@ -94,16 +96,21 @@
/**
* When we read the data, did we hit end of file?
*
- * @return true if no data was read because we were at the end of
- * the file, else false
- *
- * @exception IOException
+ * @return true if the EoF was hit during this block, or
+ * false if not. If you have a dodgy short last block, then
+ * it's possible to both have data, and also hit EoF...
*/
- public boolean eof()
- throws IOException
- {
+ public boolean eof() {
return _eof;
}
+ /**
+ * Did we actually find any data to read? It's possible,
+ * in the event of a short last block, to both have hit
+ * the EoF, but also to have data
+ */
+ public boolean hasData() {
+ return _hasData;
+ }
/* ********** START implementation of ListManagedBlock ********** */
@@ -117,7 +124,7 @@
public byte [] getData()
throws IOException
{
- if (eof())
+ if (! hasData())
{
throw new IOException("Cannot return empty data");
}
Modified: poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlockList.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlockList.java?rev=658285&r1=658284&r2=658285&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlockList.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/storage/RawDataBlockList.java Tue May 20 08:42:16 2008
@@ -51,12 +51,16 @@
while (true)
{
RawDataBlock block = new RawDataBlock(stream, bigBlockSize);
+
+ // If there was data, add the block to the list
+ if(block.hasData()) {
+ blocks.add(block);
+ }
- if (block.eof())
- {
+ // If the stream is now at the End Of File, we're done
+ if (block.eof()) {
break;
}
- blocks.add(block);
}
setBlocks(( RawDataBlock [] ) blocks.toArray(new RawDataBlock[ 0 ]));
}
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=658285&r1=658284&r2=658285&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java Tue May 20 08:42:16 2008
@@ -130,7 +130,7 @@
* The other is to fix the handling of the last block in
* POIFS, since it seems to be slight wrong
*/
- public void DISABLEDtestShortLastBlock() throws Exception {
+ public void testShortLastBlock() throws Exception {
String[] files = new String[] {
"ShortLastBlock.qwp", "ShortLastBlock.wps"
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org