nick        2005/08/07 08:26:26

  Modified:    src/scratchpad/src/org/apache/poi/hslf/record
                        StyleTextPropAtom.java
  Log:
  Better handle the case of there not being enough data in the record to form
  a final CharacterStyle
  
  Revision  Changes    Path
  1.3       +18 -3     
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
  
  Index: StyleTextPropAtom.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StyleTextPropAtom.java    1 Aug 2005 17:36:52 -0000       1.2
  +++ StyleTextPropAtom.java    7 Aug 2005 15:26:26 -0000       1.3
  @@ -92,7 +92,11 @@
                // While we have the data, grab the character styles
                Vector cp = new Vector();
                int cpos = 0;
  -             while(cpos <= len-8-10-8) { // Min size is 8, then 8+10 in
  +             int oldCpos = 0;
  +             boolean overshot = false;
  +
  +             // Min size is 8, everything starts 8+10 in to the record
  +             while((cpos <= len-8-10-8) && !overshot) { 
                        CharacterStyle cs;
                        
                        short clen = 
LittleEndian.getShort(source,start+8+10+cpos);
  @@ -108,14 +112,25 @@
                                cpos += 4;
                                cs = new CharacterStyle(clen,s1,s2,(short)0);
                        }
  -                     cp.add(cs);
  +
  +                     // Only add if it won't push us past the end of the 
record
  +                     if(cpos <= (len-8-10)) {
  +                             cp.add(cs);
  +                             oldCpos = cpos;
  +                     } else {
  +                             // Long CharacterStyle, but only enough data 
for a short one!
  +                             // Rewind back to the end of the last 
CharacterStyle
  +                             cpos = oldCpos;
  +                             overshot = true;
  +                     }
                }
                charStyles = new CharacterStyle[cp.size()];
                for(int i=0; i<charStyles.length; i++) {
                        charStyles[i] = (CharacterStyle)cp.get(i);
                }
   
  -             // Chuck anything that doesn't fit somewhere for safe keeping
  +             // Chuck anything that doesn't make a complete CharacterStyle 
  +             // somewhere for safe keeping
                reserved = new byte[len-8-10-cpos];
                
System.arraycopy(source,start+8+10+cpos,reserved,0,reserved.length);
        }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/

Reply via email to