Bug#980566: Crashes with python traceback if parsing ubuntu.csv

2022-05-05 Thread Steve McIntyre
Hi Mark,

On Thu, May 05, 2022 at 09:10:23PM +0100, Mark Hindley wrote:
>Just a small update. I think the following is better.
>
>Mark
>
>diff --git a/lsb_release.py b/lsb_release.py
>index 3e19519..472d96b 100644
>--- a/lsb_release.py
>+++ b/lsb_release.py
>@@ -45,7 +45,7 @@ def get_distro_info(origin='Debian'):
> global RELEASE_CODENAME_LOOKUP, RELEASES_ORDER, TESTING_CODENAME
> RELEASE_CODENAME_LOOKUP = { r['version']: r['series'] for r in reader if 
> r['version']}
> RELEASES_ORDER = list(RELEASE_CODENAME_LOOKUP.items())
>-RELEASES_ORDER.sort(key=lambda n: [int(v) for v in 
>re.split('([[:space:].])+', n[0]) if v.isdigit()])
>+RELEASES_ORDER.sort(key=lambda n: [int(v) for v in re.split('\D+', n[0]) 
>if v.isdigit()])
> RELEASES_ORDER = list(list(zip(*RELEASES_ORDER))[1])
> 
> if origin.lower() == 'debian':

Both of these DTRT for me, I think. Up to you which you prefer... :-)

Thanks!

-- 
Steve McIntyre, Cambridge, UK.st...@einval.com
Who needs computer imagery when you've got Brian Blessed?



Bug#980566: Crashes with python traceback if parsing ubuntu.csv

2022-05-05 Thread Mark Hindley
Just a small update. I think the following is better.

Mark

diff --git a/lsb_release.py b/lsb_release.py
index 3e19519..472d96b 100644
--- a/lsb_release.py
+++ b/lsb_release.py
@@ -45,7 +45,7 @@ def get_distro_info(origin='Debian'):
 global RELEASE_CODENAME_LOOKUP, RELEASES_ORDER, TESTING_CODENAME
 RELEASE_CODENAME_LOOKUP = { r['version']: r['series'] for r in reader if 
r['version']}
 RELEASES_ORDER = list(RELEASE_CODENAME_LOOKUP.items())
-RELEASES_ORDER.sort(key=lambda n: [int(v) for v in 
re.split('([[:space:].])+', n[0]) if v.isdigit()])
+RELEASES_ORDER.sort(key=lambda n: [int(v) for v in re.split('\D+', n[0]) 
if v.isdigit()])
 RELEASES_ORDER = list(list(zip(*RELEASES_ORDER))[1])
 
 if origin.lower() == 'debian':



Bug#980566: Crashes with python traceback if parsing ubuntu.csv

2022-05-05 Thread Mark Hindley
Steve,

Thanks for this.

I am just looking at some lsb updates and have picked your report up.

My proposed fix is attached.

Does it look sane to you? Are you able to verify?

Thanks

Mark
>From 77c66f523138fddd433096d0c411aebd75de29a5 Mon Sep 17 00:00:00 2001
From: Mark Hindley 
Date: Thu, 5 May 2022 17:26:13 +0100
Subject: [PATCH] Naturally sort release versions and ignore strings.

Closes: #980566
---
 lsb_release.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lsb_release.py b/lsb_release.py
index c03d036..3e19519 100644
--- a/lsb_release.py
+++ b/lsb_release.py
@@ -45,7 +45,7 @@ def get_distro_info(origin='Debian'):
 global RELEASE_CODENAME_LOOKUP, RELEASES_ORDER, TESTING_CODENAME
 RELEASE_CODENAME_LOOKUP = { r['version']: r['series'] for r in reader if r['version']}
 RELEASES_ORDER = list(RELEASE_CODENAME_LOOKUP.items())
-RELEASES_ORDER.sort(key=lambda n: float(n[0]))
+RELEASES_ORDER.sort(key=lambda n: [int(v) for v in re.split('([[:space:].])+', n[0]) if v.isdigit()])
 RELEASES_ORDER = list(list(zip(*RELEASES_ORDER))[1])
 
 if origin.lower() == 'debian':
-- 
2.35.1



Bug#980566: Crashes with python traceback if parsing ubuntu.csv

2021-01-20 Thread Steve McIntyre
Package: lsb-release
Version: 10.2019051400
Severity: normal

Hi!

lsb_release has two ways to work out distribution information, It
first reads the data in /usr/lib/os-release to see if all the info it
needs is there. If not, it falls back to working out the distribution
from the contents of /etc/dpkg/origins/default and then looking for
for more data in the CSV files in /usr/share/distro.info.

I'm working on a derived distribution that *used* to be based on
Ubuntu, but not any longer. We did not have all the required fields in
our version of /usr/lib/os-release (missing VERSION_CODENAME),
triggering a fallback. Due to our history, on some systems the symlink
in /etc/dpkg/origins/default still pointed to ubuntu so the code in
lsb_release.py::get_distro_info() attempted to parse ubuntu.py. It
blew up due to an odd design choice here, trying to force the version
number into a float:

Traceback:
 Traceback (most recent call last):
   File "/usr/bin/lsb_release", line 95, in 
 main()
   File "/usr/bin/lsb_release", line 59, in main
 distinfo = lsb_release.get_distro_information()
   File "/usr/lib/python3/dist-packages/lsb_release.py", line 356, in 
get_distro_information
 distinfo = guess_debian_release()
   File "/usr/lib/python3/dist-packages/lsb_release.py", line 246, in 
guess_debian_release
 get_distro_info(distinfo['ID'])
   File "/usr/lib/python3/dist-packages/lsb_release.py", line 48, in 
get_distro_info
 RELEASES_ORDER.sort(key=lambda n: float(n[0]))
   File "/usr/lib/python3/dist-packages/lsb_release.py", line 48, in 
 RELEASES_ORDER.sort(key=lambda n: float(n[0]))
 ValueError: could not convert string to float: '6.06 LTS'

We've since fixed the os-release file *and* the "default" symlink in
our version of base-files so we're not getting crashes, but the code
here is still clearly broken...

-- Package-specific info:

-- System Information:
Debian Release: 10.7
  APT prefers stable-debug
  APT policy: (500, 'stable-debug'), (500, 'stable'), (500, 'oldstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.19.0-13-amd64 (SMP w/4 CPU cores)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_GB:en (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages lsb-release depends on:
ii  distro-info-data  0.41+deb10u3
ii  python3   3.7.3-1

Versions of packages lsb-release recommends:
ii  apt  1.8.2.2

Versions of packages lsb-release suggests:
pn  lsb  

-- no debconf information