Skip to content

domainRFC support ipv6(square brackets) and fix #53179 - #53506

Merged
vdimir merged 6 commits into
ClickHouse:masterfrom
Chen768959:fix-53179
Aug 29, 2023
Merged

vdimir merged 6 commits into
ClickHouse:masterfrom
Chen768959:fix-53179

Conversation

@Chen768959

@Chen768959 Chen768959 commented Aug 17, 2023 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

domainRFC support ipv6(IP literal within square brackets)

Documentation entry for user-facing changes

fix #53179
[RFC3513] or later, is distinguished by enclosing the IP literal
within square brackets ("[" and "]").
So our domainRFC (RFC 3986) perhaps should support this.

@vdimir vdimir self-assigned this Aug 17, 2023
@vdimir vdimir added the can be tested Allows running workflows for external contributors label Aug 17, 2023
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-improvement Pull request with some product improvements label Aug 17, 2023
@robot-ch-test-poll2

robot-ch-test-poll2 commented Aug 17, 2023 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit f550afa with description of existing statuses. It's updated for the latest CI running
The full report is available here
The overall status of the commit is 🔴 failure

Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help🟢 success
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR🟢 success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process🟢 success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help🟢 success
Docker image for serversThe check to build and optionally push the mentioned image to docker hub🟢 success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here🟢 success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc🟢 success
Install packagesChecks that the built packages are installable in a clear environment🟢 success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests🟢 success
Mergeable CheckChecks if all other necessary checks are successful🟢 success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests🟢 success
Push to DockerhubThe check for building and pushing the CI related docker images to docker hub🟢 success
SQLTestThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS🟢 success
SQLancerFuzzing tests that detect logical bugs with SQLancer tool🟢 success
SqllogicRun clickhouse on the sqllogic test set against sqlite and checks that all statements are passed🟢 success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc🟢 success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc🟢 success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors🔴 failure
Style CheckRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report🟢 success
Unit testsRuns the unit tests for different release types🟢 success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts🟢 success

Comment thread src/Functions/URL/domain.h Resolved
Comment thread src/Functions/URL/domain.h Outdated
return std::string_view{};
if (!has_at_symbol)
pos = colon_pos ? colon_pos : pos;
if (has_open_bracket && has_end_bracket)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check something like has_open_bracket && !has_end_bracket as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chen768959 could you please comment on that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vdimir Sure, if has_open_bracket (and !has_end_bracket),
then dot_pos will always be nullptr
(the logic dot_pos = pos; for case : '.' will never be executed),
so checkAndReturnHost will also return std::string_view{}.
So there's no need to check has_open_bracket && !has_end_bracket. In this case, it will only return std::string_view{}.

@@ -0,0 +1,5 @@
SELECT domainRFC('[2001:db8::1]:80') FORMAT CSV;
SELECT domainRFC('[::200]:80') FORMAT CSV;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding cases with errors, e.g. with open and not closed bracket, several brackets, empty string within brackets and similar that comes to your mind.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@Chen768959
Chen768959 force-pushed the fix-53179 branch 2 times, most recently from 6d0ac50 to 3e325b1 Compare August 17, 2023 13:35
@Chen768959

Chen768959 commented Aug 18, 2023 •

Copy link
Copy Markdown
Contributor Author

"Hello, @vdimir , I have added various test scenarios that I could think of. Could you please review them again? Thank you. "

@Chen768959

Copy link
Copy Markdown
Contributor Author

@vdimir I have completed all the modifications, and I believe this pull request is now ready for review. If it's convenient for you, could you please review it again? Thank you. (Regarding the stress test check issue, it doesn't seem to be caused by my code. Should I continue updating the branch to address these issues?)"

@vdimir
vdimir merged commit a2d451d into ClickHouse:master Aug 29, 2023
otselnik pushed a commit to otselnik/ClickHouse that referenced this pull request Sep 10, 2026
`getURLHostRFC` consumes the scheme prefix and then dereferences `*pos` at
domain.h:82 (`if (*pos == '[')`) before entering its bounded scan loop at
:93. For an authority that ends exactly at the prefix, `pos == end`, so that
read is one byte past the input.

That byte is uninitialised heap rather than a harmless terminator:
`ColumnString` is not zero-terminated (ColumnString.h:40),
`ColumnString::insert` appends exactly `s.size` bytes with a plain memcpy,
StringHelpers.h:82 passes exactly `offsets[i] - prev_offset` with no -1, and
`PODArrayBase::alloc` initialises only one `pad_left` element. `pos == end`
is reachable from "//" (`pos += 2`) and from "<scheme>://" (`pos += 3`), so
`SELECT domainRFC('http://')` is enough to trigger it. On an MSan build the
server aborts; the AST fuzzer hit it in Stress test (amd_msan) after
mutating `firstSignificantSubdomain` to `domainRFC` in
00381_first_significant_subdomain.sql. MSan names :93 rather than :82
because clang if-converts the bracket test, so the first branch on the
tainted byte is the loop guard.

The read has been unguarded since a2d451d (ClickHouse#53506) added IPv6 bracket
support in 2023, and is still unguarded on 25.3, 25.8 and 26.8. The
non-RFC `getURLHost` is safe because it has no dereference between the
prefix advance and its loop, which is the shape restored here; the same
one-line shape was used by the two earlier fixes to this class in this
function, ClickHouse#86171 and ClickHouse#94851. All ten user-facing RFC functions reach the
defect through this single call site, so all ten are fixed at once.

The guard is behaviour-preserving: every `pos == end` path already returned
an empty host. Measured over 30422 generated inputs against 13 URL
functions on a fixed and a reverted build, the output is byte-identical, so
no existing reference file changes.

There is no functional oracle for the defect, and none is invented here:
the MSan build is the oracle, as it was for the test added by ClickHouse#94851.
03801_domain_empty_string_msan gains nine truncated-authority queries: the
literal that fired in CI, two further `domainRFC` literals, five more
user-facing RFC entry points, and the same input behind `materialize` for
the vectorized route. The test uses more than one truncated-authority
literal because MSan does not emit the report at every input length on the
builds measured here.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

domain() returns empty string for IPv6 and port combination

3 participants