With attached patch this time ;-)

 

Cheers,

 

Lawrence

 


From: Lawrence Jones
Sent: Tuesday, May 31, 2005 2:34 PM
To: 'dev@xmlbeans.apache.org'
Subject: Suggested patch for ArrayIndexOutOfBoundException - committers please commit for me

 

Hi all

 

In Saver.java.entitizeCommment() the last 2 lines read:

 

    if (_buf[ _lastEmitIn + _lastEmitCch - 1 ] == '-')
        i = replace( _lastEmitIn + _lastEmitCch - 1, " " );

 

but _buf is a circular buffer and it is possible for (_lastEmitIn + _lastEmitCch – 1) to be > the length of the _buf buffer. Instead the code should be:

 

    int offset = (_lastEmitIn + _lastEmitCch - 1) % _buf.length;

    if (_buf[ offset ] == '-')

        i = replace( offset, " " );

 

otherwise you can get an ArrayIndexOutOfBoundException.

 

I am attaching a patch which fixes this. I’d be grateful if one of the committers would check it in.

 

Thanks,

 

Lawrence Jones

 

Index: src/store/org/apache/xmlbeans/impl/store/Saver.java
===================================================================
--- src/store/org/apache/xmlbeans/impl/store/Saver.java (revision 178805)
+++ src/store/org/apache/xmlbeans/impl/store/Saver.java (working copy)
@@ -1347,8 +1347,9 @@
             // Because I have only replaced chars with single chars,
             // _lastEmitIn will still be ok
 
-            if (_buf[ _lastEmitIn + _lastEmitCch - 1 ] == '-')
-                i = replace( _lastEmitIn + _lastEmitCch - 1, " " );
+            int offset = (_lastEmitIn + _lastEmitCch - 1) % _buf.length;
+            if (_buf[ offset ] == '-')
+                i = replace( offset, " " );
         }
 
         private void entitizeProcinst ( )
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to