The following comment has been added to this issue:

     Author: Neil Graham
    Created: Thu, 13 May 2004 6:45 AM
       Body:
Hi Dan.  A few thoughts:  You might want to look at the way the 
http://apache.org/xml/properties/input-buffer-size property is implemented in 
Xerces-J, since that seems to aim at doing pretty much what you're after.  Xerces-J 
has a fairly different design when it comes to scanning, so it might not be directly 
relevant; but might give you some ideas.

The idea sounds good in general to me.  It sounds like you'll need to define a new 
property on the parsers for the buffer size, and maybe one for the handler.  On the 
other hand, if you can design a handler that knows how to make appropriate calls to 
the scanner's sendChars() method so that the buffer gets flushed when a maximum buffer 
size is reached, then perhaps a pluggable handler wouldn't be necessary since the 
default behaviour would always work when an application has chosen to set this limit.  

I'd also observe that XMLBuffer has to check to use the infelicitously named 
"insureCapacity()" method to make sure it's large enough; you could easily add a 
boolean to this check so that, instead of expanding its capacity if it's full, if a 
maximum size has been set then a call would be made to the handler.  This extra check 
would then only be done in the relatively unlikely situation where a buffer reaches 
its full size, so certainly wouldn't impact the performance of existing code that 
doesn't need the new property.
---------------------------------------------------------------------
View this comment:
  http://issues.apache.org/jira/browse/XERCESC-1207?page=comments#action_35524

---------------------------------------------------------------------
View the issue:
  http://issues.apache.org/jira/browse/XERCESC-1207

Here is an overview of the issue:
---------------------------------------------------------------------
        Key: XERCESC-1207
    Summary: XMLScanner::scanCharData fills XMLBuffer until out of memory
       Type: Bug

     Status: Unassigned
   Priority: Critical

    Project: Xerces-C++
 Components: 
             Non-Validating Parser
   Versions:
             2.5.0

   Assignee: 
   Reporter: Dan Rosen

    Created: Mon, 10 May 2004 10:51 AM
    Updated: Thu, 13 May 2004 6:45 AM

Description:
When parsing an XML file consisting primarily of very large (hundreds of megabytes) 
blocks of contiguous character data, XMLScanner::scanCharData() happily attempts to 
build a single XMLBuffer containing all the data. Eventually the buffer becomes so 
large that the reallocation within XMLBuffer::insureCapacity() fails, causing 
std::bad_alloc to be thrown, or a crash in memcpy (depending on compiler). The 
fundamental problem seems to be that there is no upper bound imposed on buffer length.

In the SAX model, it is acceptable to issue multiple ContentHandler::characters() 
callbacks for a single contiguous block of data. The only restriction on how this 
should be implemented is that all characters in any single event must come from the 
same external entity; no further behavior is specified. So it would be perfectly 
conformant to the SAX model to set an upper bound on the size of a single characters() 
event.

(As far as I understand, allowing an upper bound in XMLScanner::scanCharData() would 
not affect the DOM)

I'd propose that an upper bound for character buffer size be added as an optional 
parameter (with some reasonable value as a default), either in the constructor of the 
parser or in useScanner(), and that that parameter be used to inform 
XMLScanner::scanCharData() when to force a call to sendCharData() to dump the buffer 
to its client.


---------------------------------------------------------------------
JIRA INFORMATION:
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

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to