Fails to process reports: UnicodeDecodeError in is_closing_session with non-ascii env

Bug #1281084 reported by Daniel Hahler on 2014-02-17
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
apport (Ubuntu)
High
Unassigned

Bug Description

From apport.log:

ERROR: apport (pid 11229) Mon Feb 17 13:26:22 2014: called for pid 11135, signal 11, core limit 18446744073709551615
ERROR: apport (pid 11229) Mon Feb 17 13:26:22 2014: ignoring implausibly big core limit, treating as unlimited
ERROR: apport (pid 11229) Mon Feb 17 13:26:22 2014: script: /usr/bin/pydoc2.7, interpreted by /usr/bin/python2.7 (command line "/usr/bin/python2.7 /usr/bin/pydoc -k .")
ERROR: apport (pid 11229) Mon Feb 17 13:26:22 2014: Unhandled exception:
Traceback (most recent call last):
  File "/usr/share/apport/apport", line 373, in <module>
    if is_closing_session(pid, pidstat.st_uid):
  File "/usr/share/apport/apport", line 214, in is_closing_session
    env = e.read().split('\0')
  File "/usr/lib/python3.3/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 9786: ordinal not in range(128)
ERROR: apport (pid 11229) Mon Feb 17 13:26:22 2014: pid: 11229, uid: 1000, gid: 1000, euid: 0, egid: 0
ERROR: apport (pid 11229) Mon Feb 17 13:26:22 2014: environment: environ({})

ProblemType: Bug
DistroRelease: Ubuntu 13.10
Package: apport 2.12.5-0ubuntu2.2
ProcVersionSignature: Ubuntu 3.11.0-15.25-generic 3.11.10
Uname: Linux 3.11.0-15-generic x86_64
ApportVersion: 2.12.5-0ubuntu2.2
Architecture: amd64
CrashReports:
 640:1000:114:120104180:2014-02-13 00:58:41.677010970 +0100:2014-02-13 00:57:20.989009053 +0100:/var/crash/_opt_firefox_firefox.1000.crash
 640:1000:114:63870076:2014-02-13 00:00:35.972928127 +0100:2014-02-12 23:59:49.260927017 +0100:/var/crash/_usr_lib_firefox_firefox.1000.crash
 640:1000:114:14175879:2014-02-09 10:23:03.104148831 +0100:2014-02-09 10:22:57.576148699 +0100:/var/crash/_usr_bin_nautilus.1000.crash
Date: Mon Feb 17 13:27:00 2014
InstallationDate: Installed on 2012-05-28 (629 days ago)
InstallationMedia: Ubuntu 12.04 LTS "Precise Pangolin" - Release amd64 (20120425)
MarkForUpload: True
PackageArchitecture: all
SourcePackage: apport
UpgradeStatus: Upgraded to saucy on 2013-10-08 (131 days ago)
modified.conffile..etc.default.apport: [modified]
mtime.conffile..etc.default.apport: 2014-02-13T00:58:07.609010

Daniel Hahler (blueyed) wrote :
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in apport (Ubuntu):
status: New → Confirmed
Václav Šmilauer (eudoxos) wrote :

Just adding more evidence:

ERROR: apport (pid 23189) Fri Aug 29 21:15:48 2014: called for pid 23182, signal 11, core limit 18446744073709551615
ERROR: apport (pid 23189) Fri Aug 29 21:15:48 2014: ignoring implausibly big core limit, treating as unlimited
ERROR: apport (pid 23189) Fri Aug 29 21:15:48 2014: executable: /usr/bin/gmsh (command line "gmsh")
ERROR: apport (pid 23189) Fri Aug 29 21:15:48 2014: Unhandled exception:
Traceback (most recent call last):
  File "/usr/share/apport/apport", line 391, in <module>
    if is_closing_session(pid, pidstat.st_uid):
  File "/usr/share/apport/apport", line 213, in is_closing_session
    env = e.read().split('\0')
  File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 65: ordinal not in range(128)
ERROR: apport (pid 23189) Fri Aug 29 21:15:48 2014: pid: 23189, uid: 1000, gid: 1000, euid: 0, egid: 0
ERROR: apport (pid 23189) Fri Aug 29 21:15:48 2014: environment: environ({})

Václav Šmilauer (eudoxos) wrote :

Just looking at the approt source, in is_closing_session, the error is here:

with open('/proc/%s/environ' % pid) as e:
        env = e.read().split('\0')

This is normally not a problem with python3, but apport runs for some reason with the ascii encoding, which will fail when reading utf-8 encoded environment variable (in my case, it is "DEBFULLNAME=Václav Šmilauer"). So the fix is perhaps

with open('/proc/%s/environ' % pid, encoding='utf-8') as e:
        env = e.read().split('\0')

(that's what I did locally) or open the file with 'rb' and work on bytes object rather than str.

Daniel Hahler (blueyed) wrote :

I can confirm that the patch (adding ", encoding='utf-8'") from Václav fixes this issue.

Changed in apport (Ubuntu):
status: Confirmed → Triaged
importance: Undecided → High
tags: added: patch
summary: - UnicodeDecodeError in is_closing_session
+ Fails to process reports: UnicodeDecodeError in is_closing_session with
+ non-ascii env
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers