Commit Graph

24 Commits

Author SHA1 Message Date
Alexey Milovidov
1d69518c4d Useless changes 2024-05-09 02:07:04 +02:00
Raúl Marín
76b6c125ff Remove boost dep in wide integers when possible 2024-04-03 20:36:29 +02:00
Alexey Milovidov
65650809b4 Double precision of geoDistance if the arguments are Float64 2024-03-24 23:11:35 +01:00
Robert Schulze
a1c164a758
Fix a bunch of clang-tidy warnings in headers 2024-02-28 23:43:12 +00:00
Alexey Milovidov
aa757490bd Ditch tons of garbage 2023-08-09 02:19:02 +02:00
Robert Schulze
271297823a
Allow var-int encoded 64-bit integers with MSB=1
Resolves: #51486

Until now, it was illegal to encode 64-bit (unsigned) integers with
MSB=1, i.e. values > (1ULL<<63) - 1, as var-int. In more detail, the
var-int code used by ClickHouse server and client spent at most 9 bytes
per value such that 9 * 7 = 63 bits could be encoded. Some 3rd party
clients (e.g. Rust clickhouse-rs) had the same limitation, whereas other
clients understand the full range (Python clickhouse-driver).

PRs #47608 and #48628 added sanity checks as asserts or exceptions
during var-int encoding on the server side. This was considered okay as
such huge integers so far occurred only during testing (usually fuzzing)
but not in practice.

Issue #51486 is a new fuzzing issue where the exception thrown from the
sanity check led to a half-baked progress packet and as a result, a
logical error / server crash.

The only fix which is not another bandaid is to allow the full range in
var-int coding. Clients will have to allow the full range too, a note
will be added to the changelog. (the alternative was to create another
protocol version but as var-int is used all over the place this was
considered infeasible)

Review note: this is the relevant commit.
2023-07-06 20:23:23 +00:00
Robert Schulze
3f744c1e14
Cosmetics: rename template parameter 2023-07-06 14:47:40 +00:00
Robert Schulze
7644f0b37c
Cosmetics: move code around 2023-07-06 14:44:06 +00:00
Robert Schulze
3e3344d627
VarInt coding: Always perform sanity check
This is follow-up for the discussion in #48628. The sanity check against
VAR_UINT_MAX is now unconditional (independent of the build type). Let's
see how that affects performance ... I'll probably add "Unchecked"
overloads later on (to avoid clutter they are avoided for now)
2023-04-13 09:44:35 +00:00
Robert Schulze
ba67626992
Add comment about used exception code 2023-04-11 11:59:04 +00:00
Robert Schulze
bbbb55cd50
Better handling of values too large for VarInt encoding
PR #48154 introduced a sanity check in the form of a debug assertion
that the input values for VarInt encoding are not too big. Such values
should be exceptionally rare in practice but the AST fuzzer managed to
trigger the assertion regardless. The strategy to deal with such values
until now was to bypass the check by limiting the value to the maximum
allowed value (see #48412). Because a new AST Fuzzer failure appeared
(#48497) and there may be more failures in future, this PR changes the
sanity check from an assert to an exception.

Fixes: #48497
2023-04-11 07:47:33 +00:00
Robert Schulze
598b050628
AST Fuzzer: Fix assertion in TopK serialization
Problem:
  https://s3.amazonaws.com/clickhouse-test-reports/0/fa5b2bd4a5b02336bca8837c473a7124f8ecedf2/fuzzer_astfuzzerasan/report.html

The new assertion in the Varint code was introduced with (*). It rejects
values whose serialization cannot be deserialized (and this behavior
cannot be changed due to historical reasons). Such values should be
exceptionally rare in practice but AST fuzzer managers to trigger them.

The fix is similar to (**): Bypass the check by limiting the value to
the maximum allowed value.

(if AST fuzzer triggers finds more violations of the assertion, we might
consider throwing an exception instead)

(*) https://github.com/ClickHouse/ClickHouse/pull/48154
(**) https://github.com/ClickHouse/ClickHouse/pull/48154/files#diff-653c0a18dfdaa86262c78dc6b25550add0487f165b4ad053e86f530388f6203a
2023-04-05 08:07:37 +00:00
Robert Schulze
4938681f87
Fix macos build 2023-03-30 17:46:11 +00:00
Azat Khuzhin
d7d9f0cb6b Fix overflow of VarUInt format in Progress packets
Otherwise query like this, can trigger sanity check:

    WITH x AS (SELECT [], number AS a FROM numbers(9223372036854775807)), y AS (SELECT arrayLastOrNull(x -> (x >= -inf), []), arrayLastOrNull(x -> (x >= NULL), [1]), number AS a FROM numbers(1.)) SELECT [1023], * FROM x WHERE a IN (SELECT a FROM y) ORDER BY arrayLastOrNull(x -> (x >= 1025), [1048577, 1048576]) DESC NULLS LAST, '0.0000000002' ASC NULLS LAST, a DESC NULLS FIRST

CI: https://s3.amazonaws.com/clickhouse-test-reports/0/a9bcd022d5f4a5be530595dbfae3ed177b5c1972/fuzzer_astfuzzermsan/report.html
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-03-29 12:42:45 +02:00
Azat Khuzhin
36f6408ada Add sanity checks for writing number in variable length format
And just to double check:

    # var_uint 9223372036854775807
    ffffffffffffffff7f
    ffffffffffffffff7f
    ffffffffffffffff7f
    x: 9223372036854775807, y: 9223372036854775807
    # var_uint 9223372036854775808
    808080808080808080
    808080808080808080
    808080808080808080
    x: 9223372036854775808, y: 0

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-03-29 11:02:33 +02:00
Robert Schulze
4eeab9fd25
Revert "Add sanity checks for writing number in variable length format" 2023-03-21 14:24:53 +01:00
Azat Khuzhin
aa5127c2fd Add sanity checks for writing number in variable length format
And just to double check:

    # var_uint 9223372036854775807
    ffffffffffffffff7f
    ffffffffffffffff7f
    ffffffffffffffff7f
    x: 9223372036854775807, y: 9223372036854775807
    # var_uint 9223372036854775808
    808080808080808080
    808080808080808080
    808080808080808080
    x: 9223372036854775808, y: 0

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-03-15 13:08:02 +01:00
Alexander Tokmakov
70d1adfe4b
Better formatting for exception messages (#45449)
* save format string for NetException

* format exceptions

* format exceptions 2

* format exceptions 3

* format exceptions 4

* format exceptions 5

* format exceptions 6

* fix

* format exceptions 7

* format exceptions 8

* Update MergeTreeIndexGin.cpp

* Update AggregateFunctionMap.cpp

* Update AggregateFunctionMap.cpp

* fix
2023-01-24 00:13:58 +03:00
Azat Khuzhin
4e76629aaf Fixes for -Wshorten-64-to-32
- lots of static_cast
- add safe_cast
- types adjustments
  - config
  - IStorage::read/watch
  - ...
- some TODO's (to convert types in future)

P.S. That was quite a journey...

v2: fixes after rebase
v3: fix conflicts after #42308 merged
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2022-10-21 13:25:19 +02:00
Robert Schulze
b56c28d841
Replace a few uses of enable_if for SFINAE by concepts
- enable_if is usually regarded as fragile and unreadable

- C++20 concepts are much easier to read and produce more expressive
  error messages
2022-03-16 19:51:38 +01:00
Maksim Kita
e30117a3d6 Fix clang-tidy warnings in Interpreters, IO folders 2022-03-14 18:17:35 +00:00
Alexey Milovidov
fe6b7c77c7 Rename "common" to "base" 2021-10-02 10:13:14 +03:00
Artem Zuikov
51ba12c2c3
Try speedup build (#14809) 2020-09-15 12:55:57 +03:00
Ivan Lezhankin
06446b4f08 dbms/ → src/ 2020-04-03 18:14:31 +03:00