pythongssapi / python-gssapi

A Python interface to RFC 2743/2744 (plus common extensions)
ISC License
104 stars 46 forks source link

gssapi fails to import: ./Include/cpython/tupleobject.h:23: PyTuple_GET_SIZE: Assertion `PyTuple_Check(op)' failed. #327

Closed mgorny closed 1 year ago

mgorny commented 1 year ago

What went wrong?

When Python is built with assertions enabled (--with-assertions), the gssapi extension causes an assertion failure upon import:

$ python -c 'import gssapi'
python: ./Include/cpython/tupleobject.h:23: PyTuple_GET_SIZE: Assertion `PyTuple_Check(op)' failed.
Aborted (core dumped)

Backtrace:

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007f7e81a89e2f in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007f7e81a39cc2 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007f7e81a224ed in __GI_abort () at abort.c:79
#4  0x00007f7e81a22415 in __assert_fail_base (fmt=0x7f7e81b9fb98 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x7f7e82104da1 "PyTuple_Check(op)", file=file@entry=0x7f7e8211a450 "./Include/cpython/tupleobject.h", line=line@entry=23, function=function@entry=0x7f7e82146710 <__PRETTY_FUNCTION__.8> "PyTuple_GET_SIZE") at assert.c:92
#5  0x00007f7e81a325e2 in __assert_fail (assertion=assertion@entry=0x7f7e82104da1 "PyTuple_Check(op)", file=file@entry=0x7f7e8211a450 "./Include/cpython/tupleobject.h", line=line@entry=23, function=function@entry=0x7f7e82146710 <__PRETTY_FUNCTION__.8> "PyTuple_GET_SIZE") at assert.c:101
#6  0x00007f7e81f5249a in PyTuple_GET_SIZE (op=op@entry={}) at ./Include/cpython/tupleobject.h:23
#7  0x00007f7e81f52678 in method_vectorcall (method=<optimized out>, args=0x7ffcf40a4c38, nargsf=<optimized out>, kwnames={}) at Objects/classobject.c:64
#8  0x00007f7e80a2ed70 in __Pyx_PyObject_FastCallDict (func=<method at remote 0x7f7e80ce1cc0>, args=0x7ffcf40a4c38, _nargs=9223372036854775810, kwargs={}) at gssapi/raw/types.c:13221
#9  0x00007f7e80a30936 in __Pyx_Py3MetaclassPrepare (metaclass=<type at remote 0x55c4add18f60>, 
    bases=(<EnumType(_generate_next_value_=<function at remote 0x7f7e8198f420>, __module__='enum', __doc__='\n    Enum where members are also (and must be) ints\n    ', _new_member_=<built-in method __new__ of type object at remote 0x7f7e82266d00>, _use_args_=True, _member_names_=[], _member_map_={}, _value2member_map_={}, _unhashable_values_=[], _member_type_=<type at remote 0x7f7e82266d00>, _value_repr_=<wrapper_descriptor at remote 0x7f7e81d49620>, __dict__=<getset_descriptor at remote 0x7f7e819bae80>, __format__=<method_descriptor at remote 0x7f7e81d4a700>, __str__=<wrapper_descriptor at remote 0x7f7e81d49620>, __repr__=<function at remote 0x7f7e8198f560>, __new__=<function at remote 0x7f7e8198f2e0>) at remote 0x55c4add81c30>,), 
    name='RequirementFlag', qualname='RequirementFlag', mkw={}, modname='gssapi.raw.types', doc=0x0) at gssapi/raw/types.c:14327
#10 0x00007f7e80a286c0 in __pyx_pymod_exec_types (__pyx_pyinit_module=<module at remote 0x7f7e80cbbd80>) at gssapi/raw/types.c:11272
#11 0x00007f7e81f97284 in PyModule_ExecDef (module=module@entry=<module at remote 0x7f7e80cbbd80>, def=def@entry=0x7f7e80a3eb00 <__pyx_moduledef>) at Objects/moduleobject.c:419
[…]

Full backtrace: bt.txt

How do we reproduce?

git clone -b 3.11 --depth=1 https://github.com/python/cpython
git clone https://github.com/pythongssapi/python-gssapi/
cd cpython
./configure --with-assertions
make -j$(nproc)
cd ../python-gssapi
../cpython/python -m venv .venv
. .venv/bin/activate
pip install -e .
python -c 'import gssapi'

Component versions (python-gssapi, Kerberos, OS / distro, etc.)

python-gssapi 1.8.3 (@ 3a14a03d0c119ec123dc8ce9cd94714113d711bc) mit-krb5 1.21.2 Gentoo Linux amd64

mgorny commented 1 year ago

Hmm, it seems to be related to building with Cython 3. If I force Cython < 3 in pyproject.toml), it doesn't assert.

jborean93 commented 1 year ago

Thanks for confirming the Cython 3 behaviour I was just about to ask. I might just need to keep the pin at < 3 for now and push a new release.

mgorny commented 1 year ago

Hmm, this may actually be a bug in Cython. FWICS it's caused by RequirementFlag using a metaclass. Even if I replace the metaclass with plain EnumMeta, it still crashes. I'm going to try to build a standalone reproducer.

mgorny commented 1 year ago

Yep, I've got a trivial reproducer. Lemme retry with cython main and then file a bug there.

mgorny commented 1 year ago

Filed https://github.com/cython/cython/issues/5665.

jborean93 commented 1 year ago

https://github.com/pythongssapi/python-gssapi/pull/328 puts back the upper bound for Cython in the build deps as well as adds a basic check in CI to hopefully catch this issue in the future if it happens again.