Skip to content

branch-4.1: [fix](inverted index) update clucene to reject terms containing an embedded NUL byte #67179 - #67185

Merged
yiguolei merged 1 commit into
branch-4.1from
auto-pick-67179-branch-4.1
Aug 27, 2026
Merged

branch-4.1: [fix](inverted index) update clucene to reject terms containing an embedded NUL byte #67179#67185
yiguolei merged 1 commit into
branch-4.1from
auto-pick-67179-branch-4.1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #67179

…bedded NUL byte (#67179)
Bumps contrib/clucene from abe2b71a1c1 to 08d45e541fe, picking up
apache/doris-thirdparty#368.
Problem
-------
BE dies with SIGSEGV while writing an inverted index when a term
contains a
raw NUL byte in the middle (JSON \u0000 decodes to this). The crash
reproduces
on any table with an inverted index over such data, and restarts in a
loop.
Root cause
----------
In SDocumentWriter.cpp the two paths disagree on what a term is:
* addPosition() hashes and dedups with eq(p->term_, term), i.e. the FULL
string_view length, so "svc\0A" and "svc\0B" are two distinct postings;
* comparePostings() stops at CLUCENE_END_OF_WORD, so the very same two
postings compare EQUAL.
A run of mutually "equal" but distinct postings makes quickSort()'s
partition
loop peel exactly one element per call, so the recursion depth becomes
O(n)
(measured depth/N = 1.000). Each frame is 128 bytes, so ~65k levels
exhaust the
8 MiB thread stack. The stack is so far gone that the kernel cannot
build a
signal frame and force-kills the process (si_code=SI_KERNEL), which is
why no
handler output or stack trace ever reaches the log.
Fix
---
doris-thirdparty#368 rejects such terms in addPosition(), before they
can enter
the postings hash, so the degenerate equal-run can no longer form. The
row now
fails with a clear CLuceneError, which
InvertedIndexColumnWriter::add_document()
already converts into INVERTED_INDEX_CLUCENE_ERROR, instead of taking
the BE down.
Verification
------------
Reproducer: 80k terms shaped "svc\0<i>", untokenized inverted index, 8
MiB stack.
before: SIGSEGV, exit 139
after : 80000 rows rejected, exit 0, 0 postings reach the sort
Performance on clean data (the guard is one compare + a never-taken
branch):
perf instructions, 1M tokens : 10,116,997,256 -> 10,118,997,132
= +2.00 instructions/token (+0.020%)
index output (.fnm/.frq/.nrm/.tii/.tis) : byte-identical
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage59.38% (25625/43155)
Line Coverage43.86% (261787/596862)
Region Coverage39.82% (207468/521070)
Branch Coverage41.30% (95688/231689)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100% (0/0) 🎉

Increment coverage report
Complete coverage report

CategoryCoverage
Function Coverage74.14% (31175/42048)
Line Coverage58.31% (345439/592370)
Region Coverage55.07% (287679/522349)
Branch Coverage55.97% (129519/231423)

@yiguolei
yiguolei merged commit 481028a into branch-4.1Aug 27, 2026
30 of 32 checks passed
@github-actions

Copy link
Copy Markdown
ContributorAuthor

PR approved by anyone and no changes requested.

@github-actionsgithub-actionsBot added the approved Indicates a PR has been approved by one committer. label Aug 27, 2026
@github-actions

Copy link
Copy Markdown
ContributorAuthor

PR approved by at least one committer and no changes requested.

@morrySnow
morrySnow deleted the auto-pick-67179-branch-4.1 branch August 31, 2026 07:12
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approvedIndicates a PR has been approved by one committer.reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@hello-stephen@yiguolei@airborne12