Skip to content

Commit fb58e47

Browse files
Merge pull request ClickHouse#90035 from ClickHouse/backport/25.8/89929
Backport ClickHouse#89929 to 25.8: Fix buffer size calculation for base32Encode
2 parents d63f45b + 2a467ff commit fb58e47

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/Functions/FunctionBase32Conversion.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ struct Base32EncodeTraits
1111
template <typename Col>
1212
static size_t getBufferSize(Col const & src_column)
1313
{
14-
auto const src_length = src_column.getChars().size() + src_column.size();
14+
auto const src_length = src_column.getChars().size();
1515
/// Every 5 bytes becomes 8 bytes in base32
1616
/// Add padding for incomplete blocks and round up
17-
return (src_length + 4) / 5 * 8;
17+
return ((src_length + src_column.size() * 4) / 5) * 8;
1818
}
1919

2020
static size_t perform(std::string_view src, UInt8 * dst)
@@ -28,8 +28,7 @@ struct Base32DecodeTraits
2828
template <typename Col>
2929
static size_t getBufferSize(Col const & src_column)
3030
{
31-
/// This function can be used for FixedString columns so we need to take into account NULL terminator
32-
auto const string_length = src_column.getChars().size() + src_column.size();
31+
auto const string_length = src_column.getChars().size();
3332
/// decoded size is at most length of encoded (every 8 bytes becomes at most 5 bytes)
3433
return (string_length * 5 + 7) / 8;
3534
}

src/Functions/FunctionBase58Conversion.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ struct Base58DecodeTraits
2929
template <typename Col>
3030
static size_t getBufferSize(Col const & src_column)
3131
{
32-
/// This function can be used for FixedString columns so we need to take into account NULL terminator
33-
auto const string_length = src_column.getChars().size() + src_column.size();
32+
auto const string_length = src_column.getChars().size();
3433
/// decoded size is at most length of encoded (every 8 bytes becomes at most 6 bytes)
3534
return (string_length * 6 + 7) / 8;
3635
}

tests/queries/0_stateless/03714_base32_base58_short_string.reference

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Tags: no-fasttest
2+
3+
SELECT base32Encode(randomString(1, 100)) FROM numbers(1000) FORMAT Null;
4+
SELECT base58Encode(randomString(1, 100)) FROM numbers(1000) FORMAT Null;

0 commit comments

Comments
 (0)