hookutils.py usage of startswith() assumes strings, but objects are bytes

Bug #1192899 reported by James Hunt
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
apport (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

Bug 1190526 has an associated HookError_ubuntu.txt containing:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport/report.py", line 197, in _run_hook
    symb['add_info'](report, ui)
  File "/usr/share/apport/general-hooks/ubuntu.py", line 92, in add_info
    apport.hookutils.attach_conffiles(report, package, ui=ui)
  File "/usr/lib/python3/dist-packages/apport/hookutils.py", line 132, in attach_conffiles
    if contents == '[deleted]' or contents.startswith('[inaccessible'):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

The python3-specific problem seems to be that startswith() is expecting a value of the same type as 'contents'. The code assumes contents is a string, but its is a byte tuple.

A fix therefore might be "b'[inaccessible'" like this:

    if contents == '[deleted]' or contents.startswith(b'[inaccessible'):

However, I haven't checked all other instances of startswith().

Revision history for this message
Martin Pitt (pitti) wrote :

This happens for conffiles which are binary data (ugh!), so we just need to check for that condition.

Changed in apport:
status: New → In Progress
affects: apport → apport (Ubuntu)
Changed in apport (Ubuntu):
assignee: nobody → Martin Pitt (pitti)
Revision history for this message
Martin Pitt (pitti) wrote :

Ah no, the contents of conffiles is always being delivered as bytes, to also cover non-UTF8 ones.

Revision history for this message
Martin Pitt (pitti) wrote :

Fixed in trunk r2654.

Changed in apport (Ubuntu):
assignee: Martin Pitt (pitti) → nobody
status: In Progress → Fix Committed
importance: Undecided → Medium
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apport - 2.10.2-0ubuntu2

---------------
apport (2.10.2-0ubuntu2) saucy; urgency=low

  [ Brian Murray ]
  * data/general-hooks/ubuntu.py:
    - Resolve crash in duplicate signature calculation when the package is not
      installed (LP: #1184121)
    - Remove unusable check for previous package install failures
    - Fix indentation of package-conflict check

  [ Martin Pitt ]
  * Raise python-apport's "Suggests: python launchpadlib" to Depends:, as the
    only reason why to install this package is for apport-collect these days.
    (LP: #1192330)
  * Merge from trunk:
    - hookutils.py, attach_conffiles(): Fix check for inaccessible or modified
      conffiles. (LP: #1192899)
    - Updated translations from LP.
  * etc/apport/crashdb.conf: Enable crash reports on Launchpad for saucy.
 -- Martin Pitt <email address hidden> Fri, 21 Jun 2013 07:16:00 +0200

Changed in apport (Ubuntu):
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.