Skip to content

[8.4] [MOD-18088] strconv: fix heap-buffer-overflow read in unicode_tolower for a dangling multi-byte UTF-8 lead byte - #11489

Merged
redisearch-backport-pull-request[bot] merged 1 commit into
8.4from
backport-agent/pr-11202-to-8.4
Sep 18, 2026
Merged

redisearch-backport-pull-request[bot] merged 1 commit into
8.4from
backport-agent/pr-11202-to-8.4

Conversation

@redisearch-backport-pull-request

@redisearch-backport-pull-request redisearch-backport-pull-request Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #11202 to 8.4.

Original PR

Cherry-pick result

  • Resolved 1 conflict(s) — see Conflict Log below.

Conflict Log

tests/pytests/test_tags.py

  • Conflict: The end-of-file append includes master-only test context absent from the release branch, alongside the new invalid-UTF-8 regression test.
  • Why it conflicted: 8.4 lacks the preceding testTagSuffixTrieInfoOverhead test from master and the earlier query-flow test additions; its TAG test file ends at a different test.
  • Resolution: Preserved the release branch file verbatim and appended only the original commit’s 63 added lines: _INVALID_UTF8_LEAD, _assertSurvivesInvalidUtf8TagToken, and testTagInvalidUtf8LoweringOverflow. Excluded unrelated master tests from the conflict. The strconv fix and C++ regression tests applied automatically.
  • Rationale: The appended regression retains the original exact-token, prefix, and wildcard cases without importing unrelated coverage or features. No builds or tests were run, as requested; CI must validate the backport.

Release notes

  • This PR requires release notes
  • This PR does not require release notes

🤖 Generated by the auto-backport workflow.

… for a dangling multi-byte UTF-8 lead byte (#11202)

* test_tags: add regression test reproducing a tag lowering overread

unicode_tolower (src/util/strconv.h) decodes a case-insensitive tag token
with nu_utf8_read, which has no bounds checking: for a lead byte >= 0xf0
it unconditionally reads the 3 bytes following it (utf8_4b in
deps/libnu/utf8_internal.h). A token ending in such a byte -- valid or
not, 0xf0-0xff all dispatch to the same 4-byte path -- makes the decoder
read past the token's allocation.

Add testTagInvalidUtf8LoweringOverflow, covering the exact-token, prefix,
and wildcard branches (each of which calls tag_strtolower independently
in src/query.c). The read doesn't reliably crash a plain build, so the
test's own value is as a regression guard under AddressSanitizer,
verified by CI rather than this run -- matching how a prior, unrelated
strToLowerRunes overflow fix in this codebase tests the same class of
bug (survive-and-still-serve, rather than asserting exact output).

See https://github.com/RediSearch/RediSearch/issues/11135.

* strconv: fix heap-buffer-overflow read in unicode_tolower for a dangling multi-byte UTF-8 lead byte

nu_utf8_read (deps/libnu/utf8.h) has no bounds checking: for a lead byte
declaring a 2/3/4-byte sequence it unconditionally reads that many bytes
via utf8_2b/utf8_3b/utf8_4b (deps/libnu/utf8_internal.h). Both decoding
passes in unicode_tolower (the nu_strtransformnlen measuring pass and the
main decode loop) call it once per codepoint up to the string's length, so
a lead byte near the end whose declared sequence extends past that length
reads past the caller's allocation -- for a 3- or 4-byte lead this is
genuinely out of bounds, since only the NUL terminator every caller here
supplies is ever guaranteed to exist past the string's logical length.
0xf5-0xff are not even valid UTF-8 lead bytes, but nu_utf8_read still
reads them as 4-byte leads (the dispatch only checks >= 0xf0).

This is reachable through an ordinary FT.SEARCH: a case-insensitive TAG
field lowercases its query token through this path, and any exact,
prefix, or wildcard tag token ending in such a byte triggers it.

Find how many trailing bytes belong to such a dangling sequence -- at
most 3, since UTF-8's longest sequence is 4 bytes -- before either
decoding pass runs, and exclude them: they are copied through unchanged
in the output instead of being folded, since they cannot be decoded
without reading past the allocation.

Add direct unit test coverage in test_cpp_unicode_tolower.cpp for a
dangling 2/3/4-byte lead (including a byte that is not a valid lead at
all), each pinning the exact output. The pytest regression test in the
previous commit (testTagInvalidUtf8LoweringOverflow) exercises the same
fix end-to-end through FT.SEARCH.

(cherry picked from commit e4cc48b)
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.62500% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.86%. Comparing base (052eca1) to head (91cb963).

Files with missing lines Patch % Lines
src/util/strconv.h 90.62% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              8.4   #11489      +/-   ##
==========================================
- Coverage   85.92%   85.86%   -0.06%     
==========================================
  Files         341      341              
  Lines       55078    55101      +23     
  Branches    11117    11117              
==========================================
- Hits        47325    47313      -12     
- Misses       7610     7645      +35     
  Partials      143      143              
Flag Coverage Δ
flow 84.64% <90.62%> (-0.84%) ⬇️
unit 51.32% <62.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@redisearch-backport-pull-request
redisearch-backport-pull-request Bot added this pull request to the merge queue Sep 17, 2026
Merged via the queue into 8.4 with commit 6bfc7b4 Sep 18, 2026
48 checks passed
@redisearch-backport-pull-request
redisearch-backport-pull-request Bot deleted the backport-agent/pr-11202-to-8.4 branch September 18, 2026 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport This PR was automatically backported by an agent auto-backport-conflicts There were conflicts in this automatic backport size:M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants