Skip to content

Fix bounds check for script look-ahead in - #2

Closed
yakov-olkhovskiy wants to merge 1 commit into
masterfrom
cursor/fix-scriptscanner-lookahead-bounds-c7a3
Closed

yakov-olkhovskiy wants to merge 1 commit into
masterfrom
cursor/fix-scriptscanner-lookahead-bounds-c7a3

Conversation

@yakov-olkhovskiy

Copy link
Copy Markdown
Member

This fixes an out-of-bounds look-ahead in ScriptScanner::GetOneScriptSpan (internal/getonescriptspan.cc).
GetOneScriptSpan could call:
GetUTF8LetterScriptNum(next_byte_ + take + tlen) even when take + tlen == byte_length_ (one-past-end).
Under msan, this produced use-of-uninitialized-value in CLD2::UTF8OneCharLen.
Fix: guard the look-ahead and perform it only when take + tlen < byte_length_.
CI report where the failure was observed:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99740&sha=24cadae80401a21c72645ca905fc85fe0d23fac0&name_0=PR
Sanitizer stack (preserved):

#0  __msan_warning_with_origin_noreturn
#1  CLD2::UTF8OneCharLen(char const*)                        contrib/cld2/internal/utf8statetable.h:270
#2  CLD2::GetUTF8LetterScriptNum(char const*)               contrib/cld2/internal/getonescriptspan.cc:1084
#3  CLD2::ScriptScanner::GetOneScriptSpan(...)              contrib/cld2/internal/getonescriptspan.cc:922
#4  CLD2::ScriptScanner::GetOneScriptSpanLower(...)         contrib/cld2/internal/getonescriptspan.cc:1060
#5  CLD2::DetectLanguageSummaryV2(...)                      contrib/cld2/internal/compact_lang_det_impl.cc:1817
#6  CLD2::DetectLanguageSummary(...)                        contrib/cld2/internal/compact_lang_det.cc:115
#7  DB::FunctionDetectLanguageMixed::executeImpl(...)       src/Functions/FunctionsLanguageClassification.cpp:187
...
#13 FunctionsStressTestThread::executeFunction              src/Functions/tests/gtest_functions_stress.cpp

ClickHouse SELECT statements observed to trigger this path:

SELECT detectLanguageMixed(materialize(CAST('Ðь' AS String)));
SELECT detectLanguageMixed(materialize(CAST('ނJ' AS String)));

Equivalent byte-form examples:

SELECT detectLanguageMixed(materialize(CAST(unhex('C390D18C') AS String)));
SELECT detectLanguageMixed(materialize(CAST(unhex('DE824A') AS String)));
SELECT detectLanguageMixed(materialize(CAST(unhex('05DE824A') AS String)));

@Algunenano

Copy link
Copy Markdown
Member

I think #3 is more complete. I'll merge that one and update the submodule

@yakov-olkhovskiy

Copy link
Copy Markdown
Member Author

closing in favor of #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants