🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.bugs.dist
Article #6358

Bug#1155492: apt-xapian-index: an empty relationship field aborts the entire index rebuild

#6358
From: Robert August Vincent II
Date: Thu, 26 Nov 2026 22:40
218 lines
12146 bytes
Package: apt-xapian-index
Version: 0.59
Severity: important
Tags: patch upstream

Dear Maintainer,

update-apt-xapian-index fails on this system and cannot succeed, leaving the
machine with no package index at all:

  File "/usr/lib/python3/dist-packages/axi/indexer.py", line 604, in get_document_from_apt
    addon.obj.index(document, pkg)
  File "/usr/share/apt-xapian-index/plugins/relations.py", line 132, in index
    self._index_rel(pfx, val, document)
  File "/usr/share/apt-xapian-index/plugins/relations.py", line 116, in _index_rel
    doc.add_term(pfx + name.split(None, 1)[0])
IndexError: list index out of range

The cause is in the relations plugin:

    for name in self.re_split.split(val):
        doc.add_term(pfx + name.split(None, 1)[0])

re.split() returns [""] for an empty string, and "".split(None, 1) is [], so
indexing [0] raises IndexError whenever a token is empty. That happens when a
relationship field is PRESENT BUT EMPTY - "Depends:" with nothing after the
colon - and equally for a stray or trailing separator, as in "Depends: libc6,".
The caller only skips a field that is absent (rec.get(field, None) returns None
and continues), so a field that exists with an empty value reaches this code.

What makes it worth reporting is the blast radius rather than the typo. One
document is built per package, so the exception propagates out of
get_document_from_apt() through buildIndex() and rebuild(), and the whole
rebuild dies. A single malformed field in any package in any configured
repository is therefore enough to leave the system with no index, failing
identically on every subsequent run, after spending the CPU and memory to get
there (about 5 seconds and 164 MB here).

This is not hypothetical. On this machine eleven packages from a third-party
apt repository each ship "Depends:" with an empty value, and
apt-xapian-index.service had never once completed. I have reported the empty
field to that repository separately - it should not emit it - but the plugin
should not be destroyed by it either.

The patch below skips empty tokens. index() and indexDeb822() both funnel
through _index_rel(), so it covers the apt and the Deb822 paths, and that is
the only occurrence of the pattern in the tree. With it applied the indexer
completes in 17 seconds on this machine against the same packages.

It also adds TestRelationsPlugin to test/test_indexer.py, covering an empty
field, a whitespace-only field, a trailing separator and a doubled separator
alongside the ordinary and alternative-dependency cases. Four of the six fail
against the current code with the IndexError above; all six pass with the
patch, under nose2:

  testAlternatives (test_indexer.TestRelationsPlugin) ... ok
  testDoubledSeparator (test_indexer.TestRelationsPlugin) ... ok
  testEmptyField (test_indexer.TestRelationsPlugin) ... ok
  testOrdinaryField (test_indexer.TestRelationsPlugin) ... ok
  testTrailingSeparator (test_indexer.TestRelationsPlugin) ... ok
  testWhitespaceOnlyField (test_indexer.TestRelationsPlugin) ... ok

A note on running them. "./runtests" could not collect them here, and the
four existing TestIndexer tests error on this Python, so I ran nose2 from
inside test/ instead:

  cd test && python3 -m nose2 -v test_indexer

Neither of those is caused by this patch - my commit only appends to
test/test_indexer.py and removes no line from it - and both are reported
separately so that this one stays about the IndexError and its fix.

-- System Information:
Distribution: Ubuntu 26.10 (stonking)
Architecture: amd64
Python: 3.14.8
apt-xapian-index: 0.59

From 74f3b7f595e5db40847e2933c1c2103b0543d4a5 Mon Sep 17 00:00:00 2001
From: Robert August Vincent II <pillarsdotnet@gmail.com>
Date: Thu, 26 Nov 2026 17:00:38 -0500
Subject: [PATCH] relations: don't abort the whole index on an empty
 relationship field

_index_rel() indexed [0] of the result of splitting each token, but
re.split() returns [""] for an empty string and "".split() is [], so a
relationship field that is present but EMPTY raised IndexError:

  File "plugins/relations.py", line 116, in _index_rel
    doc.add_term(pfx + name.split(None, 1)[0])
  IndexError: list index out of range

The caller skips only a field that is absent - rec.get(field, None) returns
None and continues - so a field that exists with nothing after the colon
reaches this code. A stray or trailing separator does the same, as in
"Depends: libc6,".

The consequence is out of proportion to the cause. One document is built per
package, so the exception propagates out of get_document_from_apt() through
buildIndex() and rebuild(), and the entire index rebuild dies. A single
malformed field in any package in any configured repository leaves the
machine with no index at all, failing identically on every subsequent run,
and update-apt-xapian-index spends its CPU and memory before getting there.

Observed in the wild on Ubuntu 26.10 with apt-xapian-index 0.59: seven
packages from a third-party apt repository each ship "Depends:" with an empty
value, and apt-xapian-index.service had never once completed on that machine.
With this change it completes in 17 seconds.

Both index() and indexDeb822() funnel through _index_rel(), so this covers
the apt and the Deb822 paths, and it is the only occurrence of the pattern in
the tree.

Adds TestRelationsPlugin covering an empty field, a whitespace-only field, a
trailing separator and a doubled separator, alongside the ordinary and
alternative-dependency cases. Four of the six fail with the original code.
---
 plugins/relations.py | 20 +++++++++++++++-
 test/test_indexer.py | 56 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/plugins/relations.py b/plugins/relations.py
index aeb88c8..cc2349f 100644
--- a/plugins/relations.py
+++ b/plugins/relations.py
@@ -113,7 +113,25 @@ class Relations:
         @pfx
         """
         for name in self.re_split.split(val):
-            doc.add_term(pfx + name.split(None, 1)[0])
+            # Skip empty tokens instead of indexing [0] of an empty list.
+            #
+            # re.split() returns [""] for an empty string, and "".split() is
+            # [], so a relationship field that is PRESENT BUT EMPTY - say
+            # "Depends:" with nothing after the colon - raised IndexError
+            # here. The same happens for a stray or trailing separator, as in
+            # "Depends: libc6,".
+            #
+            # The caller only skips a field that is absent, so an empty one
+            # reaches this point, and because one document is built per
+            # package the exception propagated out of buildIndex() and
+            # aborted the entire index rebuild. A single malformed field in
+            # any package in any configured repository was therefore enough
+            # to leave the machine with no index at all, failing identically
+            # on every subsequent run.
+            words = name.split(None, 1)
+            if not words:
+                continue
+            doc.add_term(pfx + words[0])
 
     def index(self, document, pkg):
         """
diff --git a/test/test_indexer.py b/test/test_indexer.py
index 72b8c5b..b7ed71d 100644
--- a/test/test_indexer.py
+++ b/test/test_indexer.py
@@ -317,3 +317,59 @@ class TestIndexer(tools.AxiTestBase):
 
 if __name__ == '__main__':
     unittest.main()
+
+
+class TestRelationsPlugin(unittest.TestCase):
+    """
+    The relations plugin indexes one term per package named in a
+    relationship field. A field that is present but empty, or that carries a
+    stray or trailing separator, used to raise IndexError here and abort the
+    whole index rebuild - see plugins/relations.py.
+    """
+
+    def setUp(self) -> None:
+        import importlib.util
+
+        path = os.path.join(
+            os.environ.get("AXI_PLUGIN_DIR", "plugins"), "relations.py"
+        )
+        spec = importlib.util.spec_from_file_location("axi_relations", path)
+        assert spec is not None and spec.loader is not None
+        module = importlib.util.module_from_spec(spec)
+        spec.loader.exec_module(module)
+        self.plugin = module.init()
+
+    class FakeDoc:
+        def __init__(self) -> None:
+            self.terms: list[str] = []
+
+        def add_term(self, term: str) -> None:
+            self.terms.append(term)
+
+    def _index(self, value: str) -> list[str]:
+        doc = self.FakeDoc()
+        self.plugin._index_rel("XRD", value, doc)
+        return doc.terms
+
+    def testOrdinaryField(self) -> None:
+        self.assertEqual(
+            self._index("libc6 (>= 2.39), libgcc-s1 (>= 4.2)"),
+            ["XRDlibc6", "XRDlibgcc-s1"],
+        )
+
+    def testAlternatives(self) -> None:
+        self.assertEqual(self._index("foo | bar"), ["XRDfoo", "XRDbar"])
+
+    def testEmptyField(self) -> None:
+        # "Depends:" with nothing after it. Observed in the wild from a
+        # third-party repository, and previously an IndexError.
+        self.assertEqual(self._index(""), [])
+
+    def testTrailingSeparator(self) -> None:
+        self.assertEqual(self._index("libc6,"), ["XRDlibc6"])
+
+    def testDoubledSeparator(self) -> None:
+        self.assertEqual(self._index("libc6,, libssl3"), ["XRDlibc6", "XRDlibssl3"])
+
+    def testWhitespaceOnlyField(self) -> None:
+        self.assertEqual(self._index("   "), [])
-- 
2.55.0
Technical Details
Message-ID: <O3Qid-elrv-7@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod
From: Robert August Vincent II <pillarsdotnet@gmail.com>
Newsgroups: linux.debian.bugs.dist
Subject: Bug#1155492: apt-xapian-index: an empty relationship field aborts the entire index rebuild
Date: Thu, 26 Nov 2026 23:40:01 +0100
Message-ID: <O3Qid-elrv-7@gated-at.bofh.it>
X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org  Thu Nov 26 22:37:10 2026
Old-Return-Path: <debbugs@buxtehude.debian.org>
X-Spam-Flag: NO
X-Spam-Score: -0.547
Reply-To: Robert August Vincent II <pillarsdotnet@gmail.com>, 1155492@bugs.debian.org
Resent-To: debian-bugs-dist@lists.debian.org
Resent-Cc: ilu@solydxk.com
X-Debian-Pr-Message: report 1155492
X-Debian-Pr-Package: apt-xapian-index
X-Debian-Pr-Keywords: patch upstream
X-Debian-Pr-Source: apt-xapian-index
X-Gm-Message-State: APuU4Z9FYf1Q4Q6Ki4tZ9foH9+r4ujHoDhgetrzrjQRWqVZYesVUpM2q
	nn1MqLzMHLJ/QtRv9vpGeuSZJ/SjNcwPZB5K5Lm+1kD+NQ4b6UVHd0sbk4oG6YQ=
X-Gm-Gg: AZFdTZfiWcSv1GHcRb0a3mmycwAoksx9fo5XcSqDd4plRdY7VDj0Xzj0DrebqhTHtZc
	kmjwUJ2Mm7jz7Lxxr8kHqzOKKuFLSeN9YTP3GjV0sg3cGWsRgyEtEASmibRbGyFsQd0Nf5GQjtj
	hkepNoa0oGNcy47DqeGJkuXU1z1AN2+ztPwkkx2pB/bT8w7ISOSTQQL2BiNF72lmXIt2lMWE3iG
	yUJR65WhSJB5Xc5JvukD1BDBza95lTRh5xjia1Y5kLKjPKGf70kg8ljQtUiOz+LOZZ2hk24qcEq
	5vfy9UBu+uEDgX5c28LcLMe2mxJpRzJRj1S/x/zvNlussVJxrEMSvc8bnt+Nnw6GCbF4YOWKyee
	/KF+sYzFh6J63ByCu7uHHWBX0LKI3oV2eAlqURW2WgEPDdM5sCOymLBQTAr9rR9CXhYdbJBY0Mg
	NdZxV8m3ghXr5nz7lu4v8DEsQOiTMigRgpA2QhxUNrw+nmQtrlleFkt9h5lVOxiekVc02ndQ7aY
	shEEse9ky6TrCEfsxjx5v6bdqx037fJdO0/YUIDt7C2J7seWZVs/SwWYbHO2yNpQhHFvIYvHOi+
	ZxXYW1mOVuqB6dg1Aq+to22dQYofqAGSCpO9bmscEKNor1vFscHjVvUPdYn7mZV8dub0WCvMZWq
	+CsU5dzubjUOK8dE6z7Cz/Y/KV6262Z5SmMnqc8UO2ll/QQqNFc5mCxCBqzG/xn5Z0ZCYr1yrtI
	YKmmgd1BAowGr/uPBLmAsovw==
X-Received: by 2002:a05:690c:6e10:b0:8b4:dc54:1d25 with SMTP id 00721157ae682-8b52031b0ecmr74977177b3.7.1795732485954;
        Thu, 26 Nov 2026 14:34:45 -0800 (PST)
X-Debian-Message: from BTS
X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2005288
List-ID: <debian-bugs-dist.lists.debian.org>
List-URL: <https://lists.debian.org/debian-bugs-dist/>
Approved: robomod@news.nic.it
Lines: 218
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Thu, 26 Nov 2026 17:34:44 -0500
X-Original-Message-ID: <6b08b404.68c022b.60c1afa3@bobse16>