You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Rajkumar Balakrishnasamy <aw...@gmail.com> on 2014/02/13 10:42:38 UTC

Unable to read image xls files - Negative array index exception occurs in EscherBSERecord class

Hi All,
I am trying to read the corrupt image xls document using poi library.But
problem is  I am retrieving the bytesRemaining value wrongly

Actual value I am getting:
55028

Expected value:
120564

as bytes read is also 120564  which causes negative  array index exception
in the line  _remainingData = new byte[bytesRemaining].how can be it fixed?
please provide any suggestions



Code
 public int More ...fillFields(byte[] data, int offset, EscherRecordFactory
recordFactory) {

         int bytesRemaining = readHeader( data, offset );


         int pos = offset + 8;
         field_1_blipTypeWin32 = data[pos];
         field_2_blipTypeMacOS = data[pos + 1];
         System.arraycopy( data, pos + 2, field_3_uid = new byte[16], 0, 16
);
         field_4_tag = LittleEndian.getShort( data, pos + 18 );
         field_5_size = LittleEndian.getInt( data, pos + 20 );
         field_6_ref = LittleEndian.getInt( data, pos + 24 );
        field_7_offset = LittleEndian.getInt( data, pos + 28 );
         field_8_usage = data[pos + 32];
         field_9_name = data[pos + 33];
         field_10_unused2 = data[pos + 34];
         field_11_unused3 = data[pos + 35];
         bytesRemaining -= 36;

         int bytesRead = 0;
         if (bytesRemaining > 0) {
             // Some older escher formats skip this last record
             field_12_blipRecord = (EscherBlipRecord)
recordFactory.createRecord( data, pos + 36 );
             bytesRead = field_12_blipRecord.fillFields( data, pos + 36,
recordFactory );
         }
         pos += 36 + bytesRead;
         bytesRemaining -= bytesRead;

         _remainingData = new byte[bytesRemaining];  // negative array
index exception occurs here
         System.arraycopy( data, pos, _remainingData, 0, bytesRemaining );
         return bytesRemaining + 8 + 36 + (field_12_blipRecord == null ? 0
: field_12_blipRecord.getRecordSize()) ;

     }

Class:
EscherBSERecord

Method:
fillFields

Please refer the code:
http://grepcode.com/file/repo1.maven.org/maven2/org.apache.poi/poi/3.7beta3/org/apache/poi/ddf/EscherBSERecord.java

Thanks & Regards,
Rajkumar B

Re: Unable to read image xls files - Negative array index exception occurs in EscherBSERecord class

Posted by Rajkumar Balakrishnasamy <aw...@gmail.com>.
Hi Nick,

Where did it come from?
1. Source of file creation is unknown.

First, we need to know if it's a corrupted file, or if it's something we
can work around. Does the Binary File Format Validator pass it?
2.  BIFFValidation result: failed.
------------------------------------------------------------------------------------------------------------------------------
    <Type builtinType="GUID" streamName="SummaryInformation"
streamOffset="4088" hexStreamOffset="0xff8" childId="2" hexChildId="0x2">
      <Info>Built-in type "GUID": Unsigned 16-byte integer.</Info>
    </Type>
  </ParseStack>
  <LastData><![CDATA[
]]></LastData>
</BFFValidation>
-------------------------------------------------------------------------------------------------------------------------------
3. Issue id:
     1. https://issues.apache.org/bugzilla/show_bug.cgi?id=47252
     2. http://osdir.com/ml/dev-poi.apache.org/2009-05/msg00094.html
4. Not possible to attach the source doc.But the document contains lot of
images.

Where did it come from?
5. MS office excel, Kingsoft office are rendering that document properly &
Libreoffice is not rendering properly.
6. I could read the document if I saved it from MS office excel and open it
from my software.


Thanks & Regards,
Rajkumar B


On Thu, Feb 13, 2014 at 8:19 PM, Nick Burch <ap...@gagravarr.org> wrote:

> On Thu, 13 Feb 2014, Rajkumar Balakrishnasamy wrote:
>
>> I am trying to read the corrupt image xls document using poi library.But
>> problem is  I am retrieving the bytesRemaining value wrongly
>>
>> Actual value I am getting:
>> 55028
>>
>> Expected value:
>> 120564
>>
>> as bytes read is also 120564  which causes negative  array index exception
>> in the line  _remainingData = new byte[bytesRemaining].how can be it
>> fixed?
>>
>
> Looks like your file has less data in it than it ought to for a given
> record, and we're reading off the end of it
>
>  please provide any suggestions
>>
>
> First, we need to know if it's a corrupted file, or if it's something we
> can work around. Does the Binary File Format Validator pass it? Can Excel
> read it? Where did it come from?
>
> Then, you'll likely need to read the [MS-XLS] file format spec, and
> compare the values in your file to that. Are there optional bits that POI
> is always reading for example?
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: Unable to read image xls files - Negative array index exception occurs in EscherBSERecord class

Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 13 Feb 2014, Rajkumar Balakrishnasamy wrote:
> I am trying to read the corrupt image xls document using poi library.But
> problem is  I am retrieving the bytesRemaining value wrongly
>
> Actual value I am getting:
> 55028
>
> Expected value:
> 120564
>
> as bytes read is also 120564  which causes negative  array index exception
> in the line  _remainingData = new byte[bytesRemaining].how can be it fixed?

Looks like your file has less data in it than it ought to for a given 
record, and we're reading off the end of it

> please provide any suggestions

First, we need to know if it's a corrupted file, or if it's something we 
can work around. Does the Binary File Format Validator pass it? Can Excel 
read it? Where did it come from?

Then, you'll likely need to read the [MS-XLS] file format spec, and 
compare the values in your file to that. Are there optional bits that POI 
is always reading for example?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org