From c97dfba52a7b24048555eec03defb774cbdd6010 Mon Sep 17 00:00:00 2001 From: Bron Gondwana Date: Sat, 19 Sep 2020 20:25:11 +1000 Subject: [PATCH] honey_compact: don't crash on empty tables If the table is empty, calling ->next will crash. Checking ->empty on the cursor instead avoids going down that codepath Avoids a crasher in compacting when adding a Glass database with nothing but metadata in it: https://lists.xapian.org/pipermail/xapian-devel/2020-September/003384.html --- xapian-core/backends/honey/honey_compact.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/xapian-core/backends/honey/honey_compact.cc b/xapian-core/backends/honey/honey_compact.cc index 08fa84a07fe..12e92ad5477 100644 --- a/xapian-core/backends/honey/honey_compact.cc +++ b/xapian-core/backends/honey/honey_compact.cc @@ -627,13 +627,17 @@ merge_postlists(Xapian::Compactor* compactor, priority_queue, gt_type> pq; for ( ; b != e; ++b, ++offset) { auto in = *b; - auto cursor = new cursor_type(in, *offset); - if (cursor->next()) { - pq.push(cursor); - } else { + if (in->empty()) { + delete in; // Skip empty tables. - delete cursor; - } + } else { + auto cursor = new cursor_type(in, *offset); + if (cursor->next()) { + pq.push(cursor); + } else { + delete cursor; + } + } } string last_key;