libimobiledevice / libplist

A library to handle Apple Property List format in binary or XML
https://libimobiledevice.org
GNU Lesser General Public License v2.1
548 stars 304 forks source link

Assertion failed: ((node->children->count % 2) == 0), function node_to_xml, file xplist.c, line 365. #233

Closed tihmstar closed 1 year ago

tihmstar commented 1 year ago

Encountered this in the wild during work on futurerestore.

Here is a poc:

#include <stdio.h>
#include <plist/plist.h>

int main(int argc, const char * argv[]) {
    plist_t dict = plist_new_dict();
    plist_dict_set_item(dict, "a", NULL);
    char *xml = NULL;
    uint32_t xmlSize = 0;
    plist_to_xml(dict, &xml, &xmlSize);
    printf("%s\n",xml);
    return 0;
}

Setting a NULL element to a dictionary, causes plist_to_xml trigger an assert. I don't think having a key with an empty element in a dict is even legal plist, but in either case assert shouldn't be triggered. I suggest making the call to plist_dict_set_item(dict, "a", NULL); fail and not adding the key in first place.

nikias commented 1 year ago

d45396aad911d496494a587bd2d3ef20c2e8a8d0