xerces-c-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Bertoni <dbert...@apache.org>
Subject Re: BUG found in IGXMLScanner2.cpp
Date Mon, 21 Sep 2009 20:48:00 GMT
Ben Griffin wrote:
> I posted an earlier message up on 'c-users'; the problem there was to do 
> with a bad cast, so I have cross-posted to c-dev.
> 
> There are cases where (and I really don't know how) a document is 
> considered to be governed by a DTD when it's actually governed by a 
> Schema; and sometimes the element declaration is recognised as being a 
> SchemaElementDecl rather than a DTDElementDecl. IE, it is not true that 
> if fGrammarType == Grammar::DTDGrammarType then the XMLAttDef* attDef is 
> necessarily a DTDElementDecl.
I think what you mean is that an XMLElementDecl is always a 
DTDElementDecl, if the fGrammarType is Grammar::DTDGrammarType. We 
should figure out why this is happening, as that's the underlying bug.

> Because of this, there's a crash occuring after the forced cast at:
> 
> //-----------------------------------------------------------------
> //  Find this attribute within the parent element. We pass both
> //  the uriID/name and the raw QName buffer, since we don't know
> //  how the derived validator and its elements store attributes.
> else {
>     if(fGrammarType == Grammar::DTDGrammarType) {
>       attDef = ((DTDElementDecl *)elemDecl)->getAttDef ( namePtr);
>     }
> }
> //-----------------------------------------------------------------
> 
> 
> The following code (using dynamic casts) works fine (doesn't crash) - 
> the second cast (to SchemaElementDecl) IS being used in some cases.
> //-----------------------------------------------------------------
> //  Find this attribute within the parent element. We pass both
> //  the uriID/name and the raw QName buffer, since we don't know
> //  how the derived validator and its elements store attributes.
> else {
>     if(fGrammarType == Grammar::DTDGrammarType) {
>         DTDElementDecl* dtdelemDecl = dynamic_cast<DTDElementDecl *> 
> (elemDecl);
>         if (dtdelemDecl != NULL) {
>             attDef = dtdelemDecl->getAttDef(namePtr);
>         } else {
>             SchemaElementDecl* schelemDecl = 
> dynamic_cast<SchemaElementDecl *> (elemDecl);
>             if (schelemDecl != NULL) {
>                 attDef = schelemDecl->getAttDef(suffPtr, uriId);
>             }
>         }
>     }
> }
> //-----------------------------------------------------------------
Xerces-C doesn't use dynamic cast as a matter of policy, so we'll need 
to figure out why the grammar type is wrong. This could cause problems 
in other parts of the code as well.

> 
> Alternatively, if the attDef Must be a DTDElementDecl when fGrammarType 
> == Grammar::DTDGrammarType, then an error should be thrown....
> I will try to find a minimal use case, rather than the current set which 
> involves 24 grammars and several nested namespaces in the file being 
> parsed.
That would be great, thanks!

Dave

Mime
View raw message