You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Ben Griffin <be...@redsnapper.net> on 2009/09/21 14:40:41 UTC

BUG found in IGXMLScanner2.cpp

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. 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);
             }
         }
     }
}
//-----------------------------------------------------------------


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.


On 21 Sep 2009, at 11:52, Ben Griffin wrote:

> Essentially the value of fAttDefs is 0x0 but it isn't?!
>
> The method here is causing difficulties for me.
> When fAttDefs is NULL, it's value is appearing as  
> 0xfffffffe00000001, so it resolves to true and therefore the getter  
> (for a NULL object) is invoked, causing an inevitable crash.
> I am not sure why the value of fAttDefs appears as 0x0 on the right  
> side of my screen and as 0xfffffffe00000001 on the bottom.
> Maybe I am not setting a compile flag correctly?
>
> Is this something to do with 64 bit addressing? (This is XCode on  
> Snow Leopard)
>
>
>


Re: BUG found in IGXMLScanner2.cpp

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Ben,

Ben Griffin <be...@redsnapper.net> writes:

> Do you have / is there a sample for loading an xml schema and then  
> parsing a file against it?

You can add schemaLocation into the XML file and then use one of
the examples (e.g., DOMCount) to parse it with validation. If that
doesn't reproduce the problem, then, as you suggest, you will need 
to create a small test case that mimics your code.

> Alternatively I can send you the schemas and xml files - but if you  
> can't replicate the error from those, it may be a waste of time for you.

The best way would be to create a bug report and attach the files
to it:

http://xerces.apache.org/xerces-c/bug-report.html

Thanks,
	Boris

-- 
Boris Kolpackov, Code Synthesis Tools  http://codesynthesis.com/~boris/blog
Open-source XML data binding for C++:  http://codesynthesis.com/products/xsd
XML data binding for embedded systems: http://codesynthesis.com/products/xsde

Re: BUG found in IGXMLScanner2.cpp

Posted by Ben Griffin <be...@redsnapper.net>.
Hi Dave,

Do you have / is there a sample for loading an xml schema and then  
parsing a file against it?
I've narrowed the schema and xml files down - but I want to replicate  
the error in a small source sample rather than my rather large engine.
Alternatively I can send you the schemas and xml files - but if you  
can't replicate the error from those, it may be a waste of time for you.

I am currently using a DOMLSParser, but I doubt it has anything to do  
with that level of the code..

Best regards
	Ben.

>> 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


Re: BUG found in IGXMLScanner2.cpp

Posted by David Bertoni <db...@apache.org>.
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