AlanQuatermain/aqtoolkit

AQXMLParser random crashes when parsing some xml documents

Opened this issue · 2 comments

We had the issue that some of the xml documents which we were parsing caused a crash on iOS 6. The fix is to add the following line to the AQXMLParser line 1141:

p->serror = __errorCallback2;

And adding the following method to the same file:

static void __errorCallback2(void *userData, xmlErrorPtr error) {

}

The main problem was that the serror field is not initialized to any thing valid so the call stack you get when it is crashing is more or less random.
Our crashes were also only happening when we were parsing on a background thread.

This is not the correct fix. The serror pointer should not be manipulated directly, only via the call to xmlSetStructuredErrorFunc. The docs also say that it must be set on every thread, so it is possible that if otehr code does not follow that rule, the XML parser is forever broken.

With the above fix in place, I have see other threads in 3rd party library code call into my code via this pointer.

My current fix is to not set the pointer and not call xmlSetStructuredErrorFunc, so errors are handled by the generic handler.

Experimentation shows that this appears to work:

p->error = __errorCallBack;
xmlSetStructuredErrorFunc(self,__structuredErrorFunc);
p->serror = NULL;

Errors are passed to the structured error handler. Omitting the last line or assigning non-NULL causes call-backs to random places in the app's code when an error is encountered.