> On 7/25/05, Christoph Theis <[EMAIL PROTECTED]> wrote:

>> Anyway, John Wilson will be the one who can judge my idea as he is
>> the only one who really understands the parser. I will let it up to
>> him to decide if its really a bug and how to patch it.

> Even John will prefer to discuss a nice context diff.

OK, here is the diff.

The first sections adds a buffer.flush(). I had to do that because I
got an ArrayIndexOutOfBounds Exception when parsing large CDATA
sections: writing to the buffer hits the array boundary. But I dont
fully understand why that happens.

The second section is the problem I wrote about: Writing to the buffer
could overwrite the next character to read.

Regards
Christoph



Index: MinML.java
===================================================================
RCS file: /home/cvspublic/ws-xmlrpc/src/java/uk/co/wilson/xml/MinML.java,v
retrieving revision 1.3
diff -w -c -r1.3 MinML.java
*** MinML.java  18 Jan 2003 13:40:03 -0000      1.3
--- MinML.java  27 Jul 2005 04:29:20 -0000
***************
*** 357,362 ****
--- 357,363 ----
              }
  
              buffer.write(']');
+             buffer.flush();
              buffer.write(currentChar);
              continue;   // not end of CDATA section, don't change state
  
***************
*** 606,616 ****
--- 607,632 ----
      }
  
      public void write(final int c) throws IOException {
+       // flush if there is not enough space for the character
+       if (written && count == nextIn)
+         _flush();
+         
        written = true;
        chars[count++] = (char)c;
      }
  
      public void write(final char[] cbuf, final int off, final int len) throws 
IOException {
+       // flush if there is not enough space for the array
+       if (written && (count + len) > nextIn)
+           _flush();
+             
+       // Write single characters if there is still not enough space
+       if (count + len > nextIn) {
+         for (int i = 0; i < len; i++)
+           write(cbuf[off+i]);
+         return;
+       }
+         
        written = true;
        System.arraycopy(cbuf, off, chars, count, len);
        count += len;

Reply via email to