#1131556 libdpkg-perl: Dpkg::Version::version_compare is broken since version 1.22.12

#1131556#5
Date:
2026-03-22 16:13:28 UTC
From:
To:
Dear Maintainer,

* What led up to the situation?
  - In "trixie" trying to use "Dpkg::Version::version_compare" fails
  - The error was very clear:
    "Use of uninitialized value $a in string at /usr/share/perl5/Dpkg/Version.pm
line 271, <> line 266."

* The root cause is in commit (appeared before version 1.22.12):
  "a9b22de4db4d42417c4cac74e7e537f48284e731 perl: Remove function prototypes"

* Removing prototype of a sort function affects its semantics.
  From "sort" documentation in perlfunc man page:
      "If the subroutine's prototype is "($$)", the elements to be compared
       are passed by reference in @_, as for a normal subroutine."

* But the existing code still expect parameters in @_
  (which is empty after prototype removal)

* Minimal fix: re-add the missing prototype to that function

* Alternative fix: use $a and $b directly and don't assign them from @_

* My temporary workaround: wrote a small wrapper that pass $a and $b as explicit
parameters

#1131556#10
Date:
2026-03-22 19:46:51 UTC
From:
To:
Hi!

I assume this is meant in the context of "sort version_compare @versions".

Ack.

I've done this (using the signatures syntax so that the code can then
still be switched to use full sub signatures), with the attached change,
and included a matching change for Dpkg::Deps, where I noticed that it
always had that same problem (so not a regression). I'll add some unit
tests and queue these for the next dpkg upload (1.23.x), and I'll mark
the Dpkg::Version change for a stable update (1.22.x) fix.

This would mean you cannot call this with parameters, which would
break way more code I think (at least from within dpkg itself), and
turns into a way more surprising API.

Thanks for the report and investigation!

Regards,
Guillem

#1131556#15
Date:
2026-03-22 20:56:26 UTC
From:
To:
Thank a lot for the quick response.

The stable update is really useful
(as most of our build infrastructure already migrated to "trixie" but will stay
they in the next 1.5 years)

+1

Thank you again,
(meanwhile my workaround keep stuff here ticking)

#1131556#18
Date:
2026-04-11 18:59:32 UTC
From:
To:
Hi!

Bug #1131556 in package dpkg reported by you has been fixed in
the dpkg/dpkg.git Git repository. You can see the changelog below, and
you can check the diff of the fix at:

https://git.dpkg.org/cgit/dpkg/dpkg.git/diff/?id=f4941036b
We need prototypes for these functions so that they get the $a and $b
variables automatically set by sort, otherwise they get no arguments at
all.

Analysis-by: Oron Peled <Oron.Peled@harmonicinc.com>
Fixes: commit a9b22de4db4d42417c4cac74e7e537f48284e731
Closes: #1131556
Stable-Candidate: 1.22.x