You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Lawrence Jones (JIRA)" <xm...@xml.apache.org> on 2005/10/26 02:36:56 UTC

[jira] Assigned: (XMLBEANS-179) Saving xml with '&' and '<' characters in attribute values throws an ArrayIndexOutOfBoundsException

     [ http://issues.apache.org/jira/browse/XMLBEANS-179?page=all ]

Lawrence Jones reassigned XMLBEANS-179:
---------------------------------------

    Assign To: Rajiv Bala

I was unable to repro this issue using the snippet provided. But I think it depends on having the circular buffer in a particular state to start with and I could see that the code would run into this problem if you got into that state.

So the fix has been added in as of SVN checkin 327686.


> Saving xml with '&' and '<' characters in attribute values throws an ArrayIndexOutOfBoundsException
> ---------------------------------------------------------------------------------------------------
>
>          Key: XMLBEANS-179
>          URL: http://issues.apache.org/jira/browse/XMLBEANS-179
>      Project: XMLBeans
>         Type: Bug
>     Versions: Version 2, Version 1.0.3, Version 1.0.4
>  Environment: Mac OS X Panther, Java 1.4.2
>     Reporter: Olek Poplavskyy
>     Assignee: Rajiv Bala

>
> Look at this xml snippet:
>     <Net id="dbid:66754220" name="3&lt;.3V" type="POWER"/>
> It was read succesfully by xmlbeans but when attempt was made to save it, it threw an exception.
> java.lang.ArrayIndexOutOfBoundsException: 32754
> 	at org.apache.xmlbeans.impl.store.Saver$TextSaver.emit(Saver.java:1785)
> 	at org.apache.xmlbeans.impl.store.Saver$TextSaver.emitAttrHelper(Saver.java:1419)
> 	at org.apache.xmlbeans.impl.store.Saver$TextSaver.emitContainerHelper(Saver.java:1449)
> 	at org.apache.xmlbeans.impl.store.Saver$TextSaver.emitContainer(Saver.java:1352)
> 	at org.apache.xmlbeans.impl.store.Saver.processContainer(Saver.java:775)
> 	at org.apache.xmlbeans.impl.store.Saver.process(Saver.java:518)
> 	at org.apache.xmlbeans.impl.store.Saver$TextSaver.ensure(Saver.java:1658)
> 	at org.apache.xmlbeans.impl.store.Saver$TextSaver.read(Saver.java:2148)
> 	at org.apache.xmlbeans.impl.store.Saver$TextReader.read(Saver.java:2271)
> 	at org.apache.xmlbeans.impl.store.Cursor.save(Cursor.java:3118)
> 	at org.apache.xmlbeans.impl.values.XmlObjectBase.save(XmlObjectBase.java:167)
> 	at com.designadvance.template.pcb.parser.PCBLibraryWriter.writeSelfContainedMembershipTemplate(PCBLibraryWriter.java:179)
>          ...
> I found that in Saver.java in method replace() code was ignoring the fact that buffer is circular and was trying to write too much data to the end of it.
> Here is corrected code for replace method:
>         private int replace ( int i, String replacement )
>         {
>             assert replacement.length() > 0;
>             int dCch = replacement.length() - 1;
>             if (dCch == 0)
>             {
>                 _buf[ i ] = replacement.charAt( 0 );
>                 return i + 1;
>             }
>             assert _free >= 0;
>             if (dCch > _free)
>                 i = resize( dCch, i );
>             
>             assert _free >= 0;
>             assert _free >= dCch;
>             assert getAvailable() > 0;
>             if (_out > _in && i >= _out)
>             {
>                 System.arraycopy( _buf, _out, _buf, _out - dCch, i - _out );
>                 _out -= dCch;
>                 i -= dCch;
>             }
>             else
>             {
>                 assert i < _in;
>                 int availableEndChunk = _buf.length - _in;
>                 int totalToCopy = _in - i;
>                 if ( dCch < availableEndChunk )
>                 {
>                     System.arraycopy( _buf, i, _buf, i + dCch, totalToCopy );
>                     _in += dCch;
>                 }
>                 else
>                 {
>                     int numToCopyToStart = totalToCopy - availableEndChunk;
>                     System.arraycopy( _buf, _in-numToCopyToStart, _buf, 0, numToCopyToStart );
>                     System.arraycopy( _buf, i, _buf, i+dCch, availableEndChunk );
>                     _in = numToCopyToStart;
>                 }
>             }
>             replacement.getChars( 0, dCch + 1, _buf, i );
>             _free -= dCch;
>             
>             assert _free >= 0;
>             return i + dCch + 1;
>         }
>  

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org