PyObjCClass_CheckMethodList doesn't check for NULL returned by PyObjCSelector_NewNative

Issue #243 invalid
created an issue

PyObjCClass_CheckMethodList gets selector information by calling method_getTypeEncoding, passes that result to PyObjCSelector_NewNative which then calls PyObjC_FindReplacementSignature.

When method_getTypeEncoding returns NULL (documented in the objc runtime headers as a valid return value), the data passed to PyObjCSelector_NewNative and then PyObjC_FindReplacementSignature will be NULL.

PyObjC_FindReplacementSignature correctly identifies that this selector is NULL, sets the error string "Selector with NULL or too long signature", returns NULL and then PyObjCSelector_NewNative returns that same NULL to PyObjCClass_CheckMethodList.

PyObjCClass_CheckMethodList does not check for this return value or the error, and tries to add this NULL as a value to a dictionary which subsequently causes Python to crash on a NULL dereference.

PyObjC should check this return value and skip this introspection when the selector is NULL to prevent the crash (and potentially log a warning somewhere).

This issue comes up when trying to load Swift frameworks that have ObjC interfaces, due to a Swift compiler bug described in

Comments (4)

  1. Terry reporter

    FYI, this was with the macOS built-in pyobjc (version 2.5.1?). I looked at current 4.0 source and although the code has changed quite a bit, it's still calling method_getTypeEncoding but it may be checking return value of PyObjCSelector_NewNative now in all places. I'll need to audit and see if it's still possible with this version.

  2. Log in to comment