python pymtp crashes with segfault

Bug #575091 reported by Alex Jones
32
This bug affects 4 people
Affects Status Importance Assigned to Milestone
pymtp (Debian)
Fix Released
Unknown
pymtp (Ubuntu)
Fix Released
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.

Tags: patch oneiric

Related branches

Revision history for this message
Alex Jones (alex-jones) wrote :

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

Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
Huw Lewis (huw-lewis2409) wrote :
Changed in pymtp (Ubuntu):
status: New → Confirmed
Revision history for this message
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
Revision history for this message
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
Revision history for this message
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.

Revision history for this message
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
Revision history for this message
Fergal Daly (fergal) wrote : Re: [Bug 575091] Re: python pymtp crashes with segfault

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  
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.