#995118 python3-apt: TagSection: segfault in keys() on non-Unicode data

Package:
python3-apt
Source:
python-apt
Description:
Python 3 interface to libapt-pkg
Submitter:
Ansgar
Date:
2021-09-26 14:36:04 UTC
Severity:
normal
Tags:
#995118#5
Date:
2021-09-26 14:33:31 UTC
From:
To:
I was looking at a check in dak where we check that field names and
values are valid UTF-8.  dak used to try to decode the field names and
values from a `TagSection` for this, but in Python 3 everything is
already a Unicode `str`, so this check doesn't really work any longer.

I checked what `TagSection` does when fed non-UTF-8 data:

Non-UTF-8 values seem to work:

+---
| import apt_pkg
| t = apt_pkg.TagSection(b"Field: V\xe4lue\n")
| t["Field"]
| -> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 1: invalid continuation byte
+---

So we can just try to access all field values in dak and reject the
upload if a `UnicodeDecodeError` was raised for any of them.

However, non-UTF-8 field names result in a segmentation fault:

+---
| import apt_pkg
| t = apt_pkg.TagSection(b"F\xefeld: Value\n")
| t.keys()
| -> segmentation fault
+---

Ansgar