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

Cython crash when referencing objects after free() is called #241

Open dnicolson opened 11 months ago

dnicolson commented 11 months ago

The following code causes a crash because Python still holds a reference after plist_free has been called. In this instance, the crash comes after the __getitem__ method is called.

import plist

test = plist.loads(b'<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><array><string>one</string><string>two</string></array></plist>')

# Option 1
test[0], test[1] = test[1], test[0]

# Option 2
# item = test[0]
# del test[0]
# item
Assertion failed: (data), function plist_copy_node, file plist.c, line 532.
fish: Job 1, 'PYTHONPATH=/usr/local/lib/pytho…' terminated by signal SIGABRT (Abort)

This is the underlying cause of https://github.com/libimobiledevice/libimobiledevice/issues/929.