Bug 23075 - NegativeArraySizeException
Summary: NegativeArraySizeException
Status: CLOSED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HPSF (show other bugs)
Version: 1.5.1
Hardware: PC All
: P3 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-10 17:15 UTC by Igor Zelaya
Modified: 2005-03-20 17:06 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Zelaya 2003-09-10 17:15:20 UTC
I am creating a directory browser for our local intranet and decided to 
download POI to be able to access the files' property sets. At the beginning I 
was getting a NegativeArraySizeException when trying to access the file 
SummaryInformation.  when I downloaded the sourcecode I realized that properties
[5],properties[6] and properties[13] in th properties array were being 
initialized with a negative length.  to prove HPFS functionality I programed a 
workaround so that if the length was negative, it should leave that elemat in 
the array as a null Property.  This elements hold the information of: 
Applcation Name,Revision Number and Thumbnail.  I am also having problem whe 
getting the comments, since the files have comments but the SummaryInformation 
returns an empty string.
Comment 1 Rainer Klute 2003-09-11 09:32:40 UTC
Please try the latest POI release and try again. Does that help?
Comment 2 Igor Zelaya 2003-09-11 17:50:51 UTC
hi:
 
For HPFS to interpret microsoft's property set correctly, including 
multilingual support(only tried spanish tildes) I changed the 'value' variable 
assigmet in the following code:
 
            case Variant.VT_LPSTR:
            case Variant.VT_LPWSTR:
            {
                /* Read a byte string. In Java it is represented as a
                   String. The null bytes at the end of the byte
                   strings must be stripped. */
                final int first = o + DWord.LENGTH;
                int last = first + new DWord(src, o).intValue() - 1;
                o += DWord.LENGTH;
/*                while (src[last] == 0 && first <= last)
                    last--;*/
                try{
                  /*value = new String(src, first, last - first + 1);*/
                  value = new String((new String(src, first, last - first + 
1, "UTF-16LE")).getBytes(),"UTF-8");
                }
                catch(java.io.UnsupportedEncodingException ex){
                }
                break;
            }
 
To solve the NegativeArraySizeException I added an if-statement in the 
following code:

            default:
            {
              if (length > 0){
                final byte[] v = new byte[length];
                for (int i = 0; i < length; i++)
                  v[i] = src[offset + i];
                value = v;
              }
              else
                value = null;
              break;
            }

Hope this can help you guys for future releases.  Thanks,
 
Igor L. Zelaya
Senior Software Developer
Proyecto PAAR
Comment 3 Rainer Klute 2003-09-16 07:57:13 UTC
In order to fix this permanently (and to prepare a test case) I need a sample
document showing the faulty behaviour. Thanks!
Comment 4 Rainer Klute 2003-09-20 07:49:59 UTC
Reading the sample document with the current CVS HEAD worked without any
problem. Please consider an upgrade!