I agree with EAFP,[*] but crashing breaks Python semantics, so this improper use should be guarded. I'm not clear if this bug is in libarchive.so or in python-libarchive. Unless libarchive.so (possibly implicitly) states arguments validity as a precondition, the bug is theirs. However, I only report it here, for now.
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libarchive.public
>>> with libarchive.public.memory_reader(open('v2.zip').read()) as e:
... pass
...
>>> next(e)
Program received signal SIGSEGV, Segmentation fault.
0x0000000000b0eca0 in ?? ()
(gdb) bt
#0 0x0000000000b0eca0 in ?? ()
#1 0x00007ffff6403dc0 in ffi_call_unix64 () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#2 0x00007ffff6403828 in ffi_call () from /usr/lib/x86_64-linux-gnu/libffi.so.6
#3 0x00007ffff665f055 in _call_function_pointer (argcount=2, resmem=0x7fffffffd110, restype=<optimized out>, atypes=<optimized out>, avalues=0x7fffffffd0f0, pProc=0x7ffff580b590 <archive_read_next_header>, flags=4353) at /home/jmm/scratch/spu/python2.7-2.7.9/Modules/_ctypes/callproc.c:836
#4 _ctypes_callproc (pProc=pProc@entry=0x7ffff580b590 <archive_read_next_header>, argtuple=argtuple@entry=0x7ffff63ba3b0, flags=4353, argtypes=argtypes@entry=0x7ffff6398518, restype=restype@entry=0xa67480, checker=checker@entry=0x0) at /home/jmm/scratch/spu/python2.7-2.7.9/Modules/_ctypes/callproc.c:1179
#5 0x00007ffff66639b2 in PyCFuncPtr_call.lto_priv.95 (self=<optimized out>, inargs=<optimized out>, kwds=<optimized out>) at /home/jmm/scratch/spu/python2.7-2.7.9/Modules/_ctypes/_ctypes.c:3965
I agree with EAFP,[*] but crashing breaks Python semantics, so this improper use should be guarded. I'm not clear if this bug is in libarchive.so or in python-libarchive. Unless libarchive.so (possibly implicitly) states arguments validity as a precondition, the bug is theirs. However, I only report it here, for now.
[*] "It is Easier to Ask for Forgiveness than Permission" https://en.wikipedia.org/wiki/Python_syntax_and_semantics#Exceptions