mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 16:50:48 +00:00
Address ubsan on readBinary with bool
This commit is contained in:
parent
4988e387f2
commit
ee1a1d852d
@ -153,9 +153,7 @@ public:
|
||||
|
||||
void deserialize(AggregateDataPtr __restrict place, ReadBuffer & buf, std::optional<size_t> version, Arena * arena) const override
|
||||
{
|
||||
/// When deserializing a bool it might trigger UBSAN if the input is not 0 or 1, so it's better to use a Int8
|
||||
static_assert(sizeof(bool) == sizeof(Int8));
|
||||
Int8 flag = true;
|
||||
bool flag = true;
|
||||
if constexpr (serialize_flag)
|
||||
readBinary(flag, buf);
|
||||
if (flag)
|
||||
|
@ -1032,6 +1032,15 @@ template <typename T>
|
||||
requires is_arithmetic_v<T>
|
||||
inline void readBinary(T & x, ReadBuffer & buf) { readPODBinary(x, buf); }
|
||||
|
||||
inline void readBinary(bool & x, ReadBuffer & buf)
|
||||
{
|
||||
/// When deserializing a bool it might trigger UBSAN if the input is not 0 or 1, so it's better to treat it as an Int8
|
||||
static_assert(sizeof(bool) == sizeof(Int8));
|
||||
Int8 flag = 0;
|
||||
readBinary(flag, buf);
|
||||
x = (flag != 0);
|
||||
}
|
||||
|
||||
inline void readBinary(String & x, ReadBuffer & buf) { readStringBinary(x, buf); }
|
||||
inline void readBinary(Int128 & x, ReadBuffer & buf) { readPODBinary(x, buf); }
|
||||
inline void readBinary(Int256 & x, ReadBuffer & buf) { readPODBinary(x, buf); }
|
||||
|
@ -0,0 +1 @@
|
||||
ubsan 30313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233
|
@ -2,6 +2,10 @@
|
||||
SELECT finalizeAggregation(CAST(unhex('0F00000030'), 'AggregateFunction(min, String)')); -- { serverError 33 }
|
||||
SELECT finalizeAggregation(CAST(unhex('FFFF000030'), 'AggregateFunction(min, String)')); -- { serverError 33 }
|
||||
|
||||
-- UBSAN
|
||||
SELECT 'ubsan', hex(finalizeAggregation(CAST(unhex('4000000030313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233010000000000000000'),
|
||||
'AggregateFunction(argMax, String, UInt64)')));
|
||||
|
||||
-- aggThrow should check for errors in its input
|
||||
SELECT finalizeAggregation(CAST('', 'AggregateFunction(aggThrow(0.), UInt8)')); -- { serverError 32 }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user