attach_journal_errors is causing a ValueError crash

Bug #1978487 reported by Brian Murray
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Apport
Fix Released
Medium
Unassigned
apport (Ubuntu)
Fix Released
Medium
Unassigned
Kinetic
Fix Released
Medium
Unassigned

Bug Description

As seen in https://bugs.launchpad.net/ubuntu/+source/obs-studio/+bug/1978414 with ApportVersion: 2.21.0-0ubuntu2.

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport/report.py", line 205, in _run_hook
    symb['add_info'](report, ui)
  File "/usr/share/apport/general-hooks/generic.py", line 94, in add_info
    apport.hookutils.attach_journal_errors(report)
  File "/usr/lib/python3/dist-packages/apport/hookutils.py", line 740, in attach_journal_errors
    crash_time = report.get_date()
  File "/usr/lib/python3/dist-packages/problem_report.py", line 268, in get_date
    return datetime.datetime.strptime(self['Date'], '%a %b %d %H:%M:%S %Y')
  File "/usr/lib/python3.10/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/lib/python3.10/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data 'Sun Jun 12 19:52:55 2022' does not match format '%a %b %d %H:%M:%S %Y'

This bug is a regression of the fix of bug #1962454.

Tags: fr-2483
tags: added: rls-kk-incoming
tags: added: fr-2483
summary: - attach_journal_errors is create a ValueError crash
+ attach_journal_errors is causing a ValueError crash
Benjamin Drung (bdrung)
Changed in apport:
milestone: none → 2.22.0
Revision history for this message
Benjamin Drung (bdrung) wrote (last edit ):

I tried to reproduce this failure with following python snippet in a kinetic schroot:

```python
#!/usr/bin/python3
import datetime
date = 'Sun Jun 12 19:52:55 2022'
print(datetime.datetime.strptime(date, '%a %b %d %H:%M:%S %Y'))
```

Regardless how I call this script, it always succeeds to parse the date string. Example:

```
$ env -i LANGUAGE=nb_NO:nb:no_NO:no:nn_NO:nn:en LANG=nb_NO.UTF-8 ./test.py
2022-06-12 19:52:55
$ env -i LANGUAGE=C LANG=C.UTF-8 ./test.py
2022-06-12 19:52:55
$ env -i ./test.py
2022-06-12 19:52:55
```

Python's _strptime checks that the provided data_string is an instance of str. passing a wrong type to strptime can be ruled out as well.

Revision history for this message
Benjamin Drung (bdrung) wrote :

As Olivier Gayot pointed out, locale.setlocale(locale.LC_TIME, '') needs to be called to change the locale and to take the environment variable into account. So following snippet reproduces the failure:

```python
#!/usr/bin/python3
import datetime
import locale
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
date = 'Sun Jun 12 19:52:55 2022'
print(datetime.datetime.strptime(date, '%a %b %d %H:%M:%S %Y'))
```

Revision history for this message
Benjamin Drung (bdrung) wrote :
Changed in apport:
status: New → Fix Committed
Benjamin Drung (bdrung)
Changed in apport (Ubuntu):
importance: Undecided → Medium
Changed in apport:
importance: Undecided → Medium
tags: removed: rls-kk-incoming
Revision history for this message
Benjamin Drung (bdrung) wrote :
Benjamin Drung (bdrung)
Changed in apport:
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apport - 2.22.0-0ubuntu1

---------------
apport (2.22.0-0ubuntu1) kinetic; urgency=medium

  * New upstream release:
    - Replace `ProblemReport.get_date` by `ProblemReport.get_timestamp`, fixes
      regression in 2.21.0 (LP: #1978487)
    - apport-gtk: Exclude trailing dot from URL links (LP: #1978301)
    - Fix `AttributeError`: 'NoneType' object has no attribute 'write', fixes
      regression in 2.21.0 (LP: #1979211)
    - apport_python_hook: Properly handle missing modules (LP: #1774843)
    - apport_python_hook: Fix FileNotFoundError if the current directory was
      deleted (LP: #1979637)
    - apport_python_hook: Fix crash if os.getcwd() fails (LP: #1977954)
    - Replace deprecated 'imp' module (LP: #1947425)
    - whoopsie-upload-all: Fix 'EOFError' object has no attribute 'errno',
      fixes regression in 2.21.0 (LP: #1979681)
  * Fix KeyError: 'CasperMD5json'

 -- Benjamin Drung <email address hidden> Mon, 27 Jun 2022 12:03:00 +0200

Changed in apport (Ubuntu Kinetic):
status: New → Fix Released
Benjamin Drung (bdrung)
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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