You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Randy Waki <rw...@flipdog.com> on 2000/07/08 01:08:48 UTC

BUG: Infinite loop if empty doc and continue-after-fatal-error

Xerces 1.1.2 enters an infinite loop if the continue-after-fatal-error
feature is true and the input document is completely empty.

The infinite loop is in the do...while loop in
org.apache.xerces.framework.XMLDocumentScanner.EventHandler.parseSome().
I don't fully understand how the scanner works, but the following patch
seems to fix the problem:

In org.apache.xerces.framework.XMLDocumentScanner.XMLDeclDispatcher.dispatch(),
towards the end of the method, there is the if statement:

    if (fScannerState != SCANNER_STATE_END_OF_INPUT) {

Add the following else clause to the if statement:

    } else {
        fDispatcher = new EndOfInputDispatcher();
        setScannerState(SCANNER_STATE_END_OF_INPUT);
        return true;
    }

The patch causes the parser to return a childless document node which
seems to be the right thing to do here.

Also, it looks like some of the other Dispatcher inner classes might
have the same problem if an end-of-input occurs at the wrong time.

-- Randy

-------------------------------
Test Program:

import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

public class XercesInfiniteLoop
{
    public static void main(String[] args) throws Exception
    {
        DOMParser parser = new DOMParser();
        parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
        InputSource is = new InputSource(args[0]);

        System.out.println("Calling parser.parse()");
        parser.parse(is);
        System.out.println("Returned from parser.parse()");

        Document doc = parser.getDocument();
        System.out.println("First child = " + doc.getFirstChild());
    }
}

-------------------------------
XML Document:

(empty; zero bytes long)

-------------------------------
Output using Xerces 1.1.2:

C:>java XercesInfiniteLoop empty.xml
Calling parser.parse()

(enters into infinite loop)

-------------------------------
Output using patch:

C:>java XercesInfiniteLoop empty.xml
Calling parser.parse()
Returned from parser.parse()
First child = null


Re: Infinite loop if empty doc and continue-after-fatal-error

Posted by Eric Ye <er...@locus.apache.org>.
Thanks for reporting this. This is a known bug for some time. We'll see if
your fix can solve the problem.
_____


Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org

----- Original Message -----
From: "Randy Waki" <rw...@flipdog.com>
To: <xe...@xml.apache.org>
Sent: Friday, July 07, 2000 4:08 PM
Subject: BUG: Infinite loop if empty doc and continue-after-fatal-error


> Xerces 1.1.2 enters an infinite loop if the continue-after-fatal-error
> feature is true and the input document is completely empty.
>
> The infinite loop is in the do...while loop in
> org.apache.xerces.framework.XMLDocumentScanner.EventHandler.parseSome().
> I don't fully understand how the scanner works, but the following patch
> seems to fix the problem:
>
> In
org.apache.xerces.framework.XMLDocumentScanner.XMLDeclDispatcher.dispatch(),
> towards the end of the method, there is the if statement:
>
>     if (fScannerState != SCANNER_STATE_END_OF_INPUT) {
>
> Add the following else clause to the if statement:
>
>     } else {
>         fDispatcher = new EndOfInputDispatcher();
>         setScannerState(SCANNER_STATE_END_OF_INPUT);
>         return true;
>     }
>
> The patch causes the parser to return a childless document node which
> seems to be the right thing to do here.
>
> Also, it looks like some of the other Dispatcher inner classes might
> have the same problem if an end-of-input occurs at the wrong time.
>
> -- Randy
>
> -------------------------------
> Test Program:
>
> import org.apache.xerces.parsers.DOMParser;
> import org.w3c.dom.Document;
> import org.xml.sax.InputSource;
>
> public class XercesInfiniteLoop
> {
>     public static void main(String[] args) throws Exception
>     {
>         DOMParser parser = new DOMParser();
>
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error
", true);
>         InputSource is = new InputSource(args[0]);
>
>         System.out.println("Calling parser.parse()");
>         parser.parse(is);
>         System.out.println("Returned from parser.parse()");
>
>         Document doc = parser.getDocument();
>         System.out.println("First child = " + doc.getFirstChild());
>     }
> }
>
> -------------------------------
> XML Document:
>
> (empty; zero bytes long)
>
> -------------------------------
> Output using Xerces 1.1.2:
>
> C:>java XercesInfiniteLoop empty.xml
> Calling parser.parse()
>
> (enters into infinite loop)
>
> -------------------------------
> Output using patch:
>
> C:>java XercesInfiniteLoop empty.xml
> Calling parser.parse()
> Returned from parser.parse()
> First child = null
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>