Ubuntu

python pymtp crashes with segfault

Reported by Alex Jones on 2010-05-04
32
This bug affects 4 people
Affects Status Importance Assigned to Milestone
pymtp (Debian)
Fix Released
Unknown
pymtp (Ubuntu)
High
Brian Murray

Bug Description

Pymtp crashes with a segfault when running in Lucid 10.04.

The following error is logged when running /usr/share/doc/python-pymtp/examples/deviceinfo.py

segfault at 53 ip 00007eff29b39b54 sp 00007fffd5757bf8 error 4 in _ctypes.so[7eff29b32000+1d000]

This happens when either trying to list all tracks or all files.

Related branches

Alex Jones (alex-jones) wrote :

This was whilst trying to list files on a Creative Zen Vision:M.

Fergal Daly (fergal) wrote :

It seems the python code is out of sync with the C code. In particular, there are fields missing from the python struct definitions with the result that the "next" field is often incorrect, leading to following a bad pointer (not a pointer at all actually).

I've attached a patch that adds the missing "modificationdate" field to 2 of the structs. I don't know if this fixes everything but it certainly turns

python -c 'import pymtp;m=pymtp.MTP();m.connect();print m.get_filelisting(); m.disconnect()'

into something that doesn't segfault anymore. It also makes deviceinfo execute to completion too.

Huw Lewis (huw-lewis2409) wrote :

I have noticed exactly the same thing with libmtp 1.0.2 and pymtp 0.0.4-1.1 and have also created a patch to match thr libmtp.h header file. The changes I made included:
 - LIBMTP_Device: renamed interface_number to object_bitsize to match the libmtp.h name.
 - add modificationdate field c_long to LIBMTP_File
 - add modificationdate field c_long to LIBMTP_Track
 - add ALBUM and PLAYLIST values to the file type enum.

Huw Lewis (huw-lewis2409) wrote :
Changed in pymtp (Ubuntu):
status: New → Confirmed
Huw Lewis (huw-lewis2409) wrote :

What needs to happen to move this along? I am happy to do some testing, reviewing, hacking etc. Are there any unit tests for pymtp?

tags: added: patch
Fergal Daly (fergal) wrote :

Simple patch.

Changed in pymtp (Ubuntu):
status: Confirmed → Triaged
importance: Undecided → High
tags: added: oneiric
Changed in pymtp (Ubuntu):
assignee: nobody → Brian Murray (brian-murray)
status: Triaged → In Progress
Brian Murray (brian-murray) wrote :

Huw your attachment wasn't really a patch rather your full modified version of pymtp.py, subsequently I uploaded Fergal's patch. However, if there is more work to be done to get pymtp in better shape please let me know and I'll be happy to upload other patches.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package pymtp - 0.0.4-2ubuntu1

---------------
pymtp (0.0.4-2ubuntu1) oneiric; urgency=low

  * Fix crash when accessing file listing. Thanks to Fergal Daly for the
    patch. (LP: #575091)
 -- Brian Murray <email address hidden> Fri, 08 Jul 2011 13:27:06 -0700

Changed in pymtp (Ubuntu):
status: In Progress → Fix Released

FYI, this approach to C extensions is extremely brittle. While I was
happy that pymtp existed, it can be broken again at any time by the
addition or reordering of fields in the C library.

If this is to be a supported module then the packager of libmtp will
have to be involved in order to ensure that changes in libmtp also
result in changes to pymtp.

Changed in pymtp (Debian):
status: Unknown → New
Changed in pymtp (Debian):
status: New → Fix Committed
Changed in pymtp (Debian):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.