2010-09-14 16:43:00 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <iostream>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/VarInt.h>
|
|
|
|
#include <IO/WriteBufferFromString.h>
|
|
|
|
#include <IO/ReadBufferFromString.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
2010-09-14 16:43:00 +00:00
|
|
|
#include <Poco/HexBinaryEncoder.h>
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
std::cerr << "Usage: " << std::endl
|
|
|
|
<< argv[0] << " unsigned_number" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2016-08-05 02:41:41 +00:00
|
|
|
|
2024-01-13 02:48:04 +00:00
|
|
|
UInt64 x = DB::parse<UInt64>(argv[1]);
|
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 09:11:42 +00:00
|
|
|
|
|
|
|
std::cout << std::hex << std::showbase << "Input: " << x << std::endl;
|
|
|
|
|
2010-09-14 16:43:00 +00:00
|
|
|
Poco::HexBinaryEncoder hex(std::cout);
|
2023-04-11 07:47:33 +00:00
|
|
|
std::cout << "writeVarUInt(std::ostream): 0x";
|
|
|
|
DB::writeVarUInt(x, hex);
|
2010-09-14 16:43:00 +00:00
|
|
|
std::cout << std::endl;
|
2012-12-14 19:41:39 +00:00
|
|
|
|
|
|
|
std::string s;
|
|
|
|
|
|
|
|
{
|
|
|
|
DB::WriteBufferFromString wb(s);
|
2023-04-11 07:47:33 +00:00
|
|
|
DB::writeVarUInt(x, wb);
|
2012-12-14 19:41:39 +00:00
|
|
|
wb.next();
|
|
|
|
}
|
|
|
|
|
2023-04-11 07:47:33 +00:00
|
|
|
std::cout << "writeVarUInt(WriteBuffer): 0x";
|
2012-12-14 19:41:39 +00:00
|
|
|
hex << s;
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
2016-08-05 02:41:41 +00:00
|
|
|
s.clear();
|
|
|
|
s.resize(9);
|
|
|
|
|
2023-04-11 07:47:33 +00:00
|
|
|
s.resize(DB::writeVarUInt(x, s.data()) - s.data());
|
2016-08-05 02:41:41 +00:00
|
|
|
|
2023-04-11 07:47:33 +00:00
|
|
|
std::cout << "writeVarUInt(char *): 0x";
|
2016-08-05 02:41:41 +00:00
|
|
|
hex << s;
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
2024-01-13 02:48:04 +00:00
|
|
|
UInt64 y = 0;
|
2016-08-05 02:41:41 +00:00
|
|
|
|
2012-12-14 19:41:39 +00:00
|
|
|
DB::ReadBufferFromString rb(s);
|
|
|
|
DB::readVarUInt(y, rb);
|
|
|
|
|
2023-04-11 07:47:33 +00:00
|
|
|
std::cerr << "Input: " << x << ", readVarUInt(writeVarUInt()): " << y << std::endl;
|
2016-08-05 02:41:41 +00:00
|
|
|
|
2010-09-14 16:43:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|