AlanQuatermain / aqtoolkit

A toolkit consisting of a bunch of generally useful routines and extensions I wrote when putting together other projects.
http://blog.alanquatermain.net/code
BSD 3-Clause "New" or "Revised" License
785 stars 149 forks source link

AQXMLParser random crashes when parsing some xml documents #18

Open vkodocha opened 11 years ago

vkodocha commented 11 years ago

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.

bagelturf commented 11 years ago

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.

bagelturf commented 11 years ago

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.