• Bug#922223: apt: terminate called after throwing an instance of 'std::l

    From Kamil Ignacak@21:1/5 to All on Tue Mar 25 22:10:01 2025
    Hi!

    tl;dr: this bug is already fixed with this commit: https://salsa.debian.org/apt-team/apt/-/commit/df2d614900476920671779f27fcc4143d3c1b5b7




    A. Reproduction in debian/stretch with apt 1.4.9

    1. Have Debian 9 / stretch installed.
    2. Compile apt 1.4.9 packages from revision 2f984e7730b341879db3cfd330c8443e48e6efb0 with "debuild -i -us -uc -b"
    and install them
    3. Clone repository that provides relevant glx packages
    git clone https://salsa.debian.org/nvidia-team/glx-alternatives.git
    4. Compile 0.8.8~deb9u1 packages from revision 556991a8b03d0402faab95937bf041b43d28f613 with "debuild -i -us -uc -b"
    5. Install compiled packages that are the dependencies for glx-diversions:
    sudo apt install ../glx-alternative-mesa_0.8.8~deb9u1_amd64.deb ../update-glx_0.8.8~deb9u1_amd64.deb
    6. Attempt to install the locally-built package that causes problems in
    this ticket:

    sudo apt install ../glx-diversions_0.8.8~deb9u1_amd64.deb
    [...]
    The following additional packages will be installed:
    nvidia-installer-cleanup
    The following NEW packages will be installed:
    glx-diversions nvidia-installer-cleanup
    0 upgraded, 2 newly installed, 0 to remove and 10 not upgraded.
    Need to get 19.3 kB/30.9 kB of archives.
    After this operation, 90.1 kB of additional disk space will be used.
    Do you want to continue? [Y/n]
    Get:1 /home/acerion/ticket/glx-diversions_0.8.8~deb9u1_amd64.deb
    glx-diversions amd64 0.8.8~deb9u1 [11.6 kB]
    Get:2 http://archive.debian.org/debian stretch/contrib amd64 nvidia-installer-cleanup amd64 20151021+4 [19.3 kB]
    [...]
    Unpacking glx-diversions (0.8.8~deb9u1) ...
    Setting up glx-diversions (0.8.8~deb9u1) ...
    terminate called after throwing an instance of 'std::logic_error'
    what(): basic_string::_M_construct null not valid
    Aborted
    7. Fix installation and uninstall glx-diversions
    sudo dpkg --configure -a
    sudo apt remove glx-diversions




    B. Session in gdb in debian/stretch with apt 1.4.9

    1. Recompile apt with 'export CXXFLAGS="-ggdb -O0"' to have access to
    inlined functions.
    2. Install recompiled apt.
    3. Run gdb from apt's source directory.
    acerion@debian:~/ticket/apt/apt$ sudo gdb --args apt install ../../glx-diversions_0.8.8~deb9u1_amd64.deb
    [...]
    (gdb) r
    Starting program: /usr/bin/apt install ../../glx-diversions_0.8.8\~deb9u1_amd64.deb
    [...]
    Unpacking glx-diversions (0.8.8~deb9u1) ...
    Setting up glx-diversions (0.8.8~deb9u1) ...
    terminate called after throwing an instance of 'std::logic_error'
    what(): basic_string::_M_construct null not valid
    Program received signal SIGABRT, Aborted.
    __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
    51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
    (gdb) bt
    [...]
    #8 0x00007ffff734c3cc in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char
    const*, std::allocator<char> const&) () from /lib/x86_64-linux-gnu/libstdc++.so.6
    #9 0x00007ffff7816921 in
    pkgCache::PkgIterator::FullName[abi:cxx11](bool const&) const (this=0x7fffffffc570, Pretty=@0x7fffffffc82f: false) at /home/acerion/ticket/apt/apt/apt-pkg/pkgcache.cc:578
    #10 0x00007ffff77b36d8 in pkgDPkgPM::ProcessDpkgStatusLine (this=0x5555558169d0, line=0x5555557e8541 "status: libglx-mesa0: not-installed") at /home/acerion/ticket/apt/apt/apt-pkg/deb/dpkgpm.cc:663
    #11 0x00007ffff77b5a1a in pkgDPkgPM::DoDpkgStatusFd
    (this=0x5555558169d0, statusfd=23) at /home/acerion/ticket/apt/apt/apt-pkg/deb/dpkgpm.cc:958
    #12 0x00007ffff77bcac8 in pkgDPkgPM::Go (this=0x5555558169d0, progress=0x555555817790) at /home/acerion/ticket/apt/apt/apt-pkg/deb/dpkgpm.cc:2060
    #13 0x00007ffff7813638 in pkgPackageManager::DoInstallPostFork (this=0x5555558169d0, progress=0x555555817790) at /home/acerion/ticket/apt/apt/apt-pkg/packagemanager.cc:1154
    #14 0x00007ffff7813736 in pkgPackageManager::DoInstall
    (this=0x5555558169d0, progress=0x555555817790) at /home/acerion/ticket/apt/apt/apt-pkg/packagemanager.cc:1186
    #15 0x00007ffff7b77fd1 in InstallPackages (Cache=..., ShwKept=false,
    Ask=false, Safety=true) at /home/acerion/ticket/apt/apt/apt-private/private-install.cc:349
    #16 0x00007ffff7b7b407 in DoInstall (CmdL=...) at /home/acerion/ticket/apt/apt/apt-private/private-install.cc:834
    #17 0x00007ffff7751836 in CommandLine::DispatchArg (this=0x7fffffffe510, Map=0x555555776790, NoMatch=true) at /home/acerion/ticket/apt/apt/apt-pkg/contrib/cmndline.cc:369
    #18 0x00007ffff7b6d568 in DispatchCommandLine (CmdL=...,
    Cmds=std::vector of length 27, capacity 32 = {...}) at /home/acerion/ticket/apt/apt/apt-private/private-cmndline.cc:556
    #19 0x0000555555556664 in main (argc=3, argv=0x7fffffffe638) at /home/acerion/ticket/apt/apt/cmdline/apt.cc:116
    (gdb) frame 9
    #9 0x00007ffff7816921 in
    pkgCache::PkgIterator::FullName[abi:cxx11](bool const&) const (this=0x7fffffffc570, Pretty=@0x7fffffffc82f: false) at /home/acerion/ticket/apt/apt/apt-pkg/pkgcache.cc:578
    warning: Source file is more recent than executable.
    578 string fullname = Name();
    (gdb) print Name()
    $1 = 0x0
    (gdb) up
    #10 0x00007ffff77b36d8 in pkgDPkgPM::ProcessDpkgStatusLine (this=0x5555558169d0, line=0x5555557e8541 "status: libglx-mesa0: not-installed") at /home/acerion/ticket/apt/apt/apt-pkg/deb/dpkgpm.cc:663 warning: Source file is more recent than executable.
    663 if (PackageOps.find(P.FullName()) != PackageOps.end())
    (gdb) print Grp.end()
    $2 = true
    (gdb) q




    C. Observations from the gdb session

    1. Code executed in frame 10 leads to Name() returning null in frame 9.
    2. Code executed in frame 10 in line 665 is running in a context where
    Grp iterator is at the end.

    I'm not evaluating the logic of code in the two places, but neither a constructor returning null nor Grp iterator being at the end look valid.

    The code executed in frame 10 can be seen here: https://salsa.debian.org/apt-team/apt/-/blame/1.4.9/apt-pkg/deb/dpkgpm.cc?ref_type=tags#L663

    3. The code in question appears to be processing "status: libglx-mesa0: not-installed" string captured from dpkg's output.

    "apt search libglx-mesa0" executed on debian/stretch returns zero
    results.

    At the same time the fix to glx-alternatives to the problem addressed in
    this ticket looks like this (it removes some kind of dependency on libglx-mesa0): https://salsa.debian.org/nvidia-team/glx-alternatives/-/commit/d4ec58a50f993c5534b9999346b0cbc9286b5e41




    D. Observations from the repo

    Current version of apt-pkg/deb/dpkgpm.cc includes additional checks that
    appear to be designed to avoid this situation. Here is a relevant
    commit: https://salsa.debian.org/apt-team/apt/-/commit/df2d614900476920671779f27fcc4143d3c1b5b7




    E. Applying patch

    After applying patch from df2d6149 on top of apt 1.4.9, and running the
    patched apt on debian/stretch, the crash no longer occurs.

    acerion@debian:~/ticket/apt/apt$ sudo apt -o "Debug::pkgDPkgProgressReporting=true" install ../../glx-diversions_0.8.8~deb9u1_amd64.deb
    [...]
    After this operation, 37.9 kB of additional disk space will be used.
    Get:1 /home/acerion/ticket/glx-diversions_0.8.8~deb9u1_amd64.deb
    glx-diversions amd64 0.8.8~deb9u1 [11.6 kB]
    Selecting previously unselected package glx-diversions.
    (Reading database ... 65383 files and directories currently installed.) Preparing to unpack .../glx-diversions_0.8.8~deb9u1_amd64.deb ...
    [...]
    got from dpkg 'status: libglx-mesa0: not-installed'
    unable to figure out which package is dpkg referring to with
    'libglx-mesa0'! (0)
    acerion@debian:~/ticket/apt/apt$
    acerion@debian:~/ticket/apt/apt$ echo $?

    0
    acerion@debian:~/ticket/apt/apt$ apt -qq list glx-diversions glx-diversions/oldoldstable 0.8.8~deb9u2 amd64 [upgradable from:
    0.8.8~deb9u1]




    F. Tests with apt 1.4.9 on debian/buster

    After compiling clean (unpatched) apt 1.4.9 on Debian 10 / buster and installing it (which required some tricks like downgrade of dpkg and
    removal of "-Rules-Requires-Root: no" from
    glx-alternatives/debian/control), I was unable to reproduce the problem.
    There was no crash of
    apt 1.4.9 running on debian/buster.

    Perhaps it's because libglx-mesa0 package is available in buster (while
    it was not available in stretch):

    root@debian:/home/acerion/ticket/glx# apt search libglx-mesa0
    [...]
    libglx-mesa0/oldoldstable 18.3.6-2+deb10u1 amd64
    free implementation of the OpenGL API -- GLX vendor library




    So it appears to me that this bug has been fixed with commit df2d6149
    and the "fix version" for this bug will be 1.6_alpha7. The code from the
    commit is still present in latest code in repo.

    Please let me know if I'm missing something in this analysis or if you
    think that I should do some more tests. If there will be no comments in
    next ~2 weeks, I will close this ticket.

    Kamil

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)