Skip to content

Conversation

@rschu1ze
Copy link
Member

@rschu1ze rschu1ze commented Jan 3, 2024

This PR reverts #58277 which reverted #57969 and addresses the feedback.

Original PR description:
Inspired by #34439, especially #34439 (comment), which was dormant for too long. This PR also uses the ada-idna library instead of a 15 year old homegrown implementation.

More specifically, this PR

Changelog category (leave one):

  • New Feature

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

Added functions punycodeEncode(), punycodeDecode(), idnaEncode() and idnaDecode() which are useful for translating international domain names to an ASCII representation according to the IDNA standard.

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR. labels Jan 3, 2024
@robot-clickhouse-ci-2
Copy link
Contributor

robot-clickhouse-ci-2 commented Jan 3, 2024

This is an automated comment for commit dd2d9ff with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Successful checks
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
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ 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
Docs CheckBuilds and tests the documentation✅ 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
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✅ success
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
Check nameDescriptionStatus
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⏳ pending
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ failure
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❌ failure

@vitlibar vitlibar self-assigned this Jan 3, 2024
@rschu1ze rschu1ze changed the title *wip* Implement IDNA and punycode encoding/decoding (2nd attempt) Implement IDNA and punycode encoding/decoding (2nd attempt) Jan 3, 2024
@rschu1ze rschu1ze marked this pull request as ready for review January 3, 2024 18:14

/// Implementation of
/// - punycode(En|De)code[OrNull](), see [1]
/// - idna(En|De)code[OrNull](), see [2, 3]
Copy link
Member

Choose a reason for hiding this comment

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

I understand about punycodeDecode but how punycodeEncode can fail? I mean why do we need punycodeEncodeOrNull?

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I see, the only way for punycode encoding to fail currently is the (weird) edge that the input is not UTF-8. But from a ClickHouse POV, the ada-idna library API simply returns "failed" and there could be further sources of errors in future (e.g. a failure to allocate memory). For these reasons, I guess we should keep punycodeEncodeOrNull(). I can make the docs more concise tomorrow.

Copy link
Member

@vitlibar vitlibar Jan 4, 2024

Choose a reason for hiding this comment

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

From looking at the code of ada-idna it seems right now it returns "failed" statuses only when there are some coding errors, and not on allocation failures. If it can't allocate it will probably just throw std::bad_alloc.

We don't usually handle too much if the input is not a proper UTF-8 string, see upperUTF8 or base64Encode. I think it's better to be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I changed the code so that these functions remain:

  • punycodeEncode(), punycodeDecode() and tryPunycodeDecode()
  • idnaEncode(), tryIdnaEncode() and idnaDecode()

This is more consistent with other SQL functions.

Yes, it is still a bit unexpected why in the case of idna encoding may fail but this is required by the algorithm and I'll document it.

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be idnaEncode(), tryIdnaDecode() and idnaDecode()?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. It is a bit confusing but it is really idnaEncode(), tryIdnaEncode() and idnaDecode().

There are actually strings that cannot be idna-encoded (in particular ones with xn-- prefix as far as I understand). idnaEncode() throws an exception then, tryIdnaEncode() returns an empty string.

And there is idnaDecode() but no tryIdnaDecode() because the IDNA decoding algorithm (as specified by the standard) requires that invalid input values are returned as is. There is no point in other error handling.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. It will probably also fail for long domains, for example

idnaEncode('1234567890123456789012345678901234567890123456789012345678901234')


const size_t utf8_length = ada::idna::utf8_length_from_utf32(value_utf32.data(), value_utf32.size());
value_utf8.resize(utf8_length);
ada::idna::utf32_to_utf8(value_utf32.data(), value_utf32.size(), value_utf8.data());
Copy link
Member

Choose a reason for hiding this comment

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

Probably it's better to reassign utf8_length to the result of ada::idna::utf32_to_utf8 here.

@rschu1ze rschu1ze force-pushed the punycode-revert-revert branch from 2161f01 to 8169b3e Compare January 5, 2024 12:19
const size_t value_length = offsets[row] - prev_offset - 1;

std::string_view value_view(value, value_length);
if (!value_view.empty()) /// to_ascii() expects non-empty input
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't idnaEncode throw an exception for an empty input?

Copy link
Member Author

Choose a reason for hiding this comment

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

Empty input is an edge case which is generally legal. ada::idna::to_ascii() handles empty inputs gracefully (it doesn't throw, it returns an empty output). The comment on l. 65 is only there because the API docs say so and I wanted to program against the API, not the implementation. In any case, it slightly simplifies the actual error handling (l. 68ff) which would otherwise be ambiguous in the empty string case.

@rschu1ze rschu1ze merged commit fb4fd29 into ClickHouse:master Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants