🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.debian.bugs.dist
1 messages
1 total messages Started by Robert August Vincent II Thu, 26 Nov 2026 22:40
Bug#1155492: apt-xapian-index: an empty relationship field aborts the entire index rebuild
#6358
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads