-
Notifications
You must be signed in to change notification settings - Fork 8.3k
base58Decode produces incorrect output #40536
Copy link
Copy link
Closed
Labels
potential bugTo be reviewed by developers and confirmed/rejected.To be reviewed by developers and confirmed/rejected.
Description
It looks like ClickHouse's base58Decode function works incorrectly.
For example, base58-encoded value 1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix should be decoded to a 32 byte array. Here is an example from python which works correctly:
$ python3 -m venv ~/.venv/base58
$ ~/.venv/base58/bin/pip install base58
$ ~/.venv/base58/bin/python3
>>> import base58
>>> base58.b58decode('1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix')
b'\x00\x0b\xe3\xe1\xeb\xa1zG?\x89\xb0\xf7\xe8\xe2I@\xf2\n\xeb\x8e\xbc\xa7\x1a\x88\xfd\xe9]K\x83\xb7\x1a\t'
>>> len(base58.b58decode('1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix'))
32
>>> base58.b58decode('1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix').hex()
'000be3e1eba17a473f89b0f7e8e24940f20aeb8ebca71a88fde95d4b83b71a09'
Clickhouse produces incorrect, 31 byte string (notice that the leading NULL byte is missing):
:) SELECT length(base58Decode('1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix')) FORMAT Vertical;
Row 1:
──────
length(base58Decode('1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix')): 31
:) select hex(base58Decode('1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix')) format Vertical;
Row 1:
──────
hex(base58Decode('1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix')): 0BE3E1EBA17A473F89B0F7E8E24940F20AEB8EBCA71A88FDE95D4B83B71A09
and decode/encode pair does not produce original value:
:) SELECT base58Encode(base58Decode('1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix')) FORMAT Vertical;
Row 1:
──────
base58Encode(base58Decode('1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix')): BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix
Does it reproduce on recent release?
Yes. The bug was reproduced on:
:) select version() format Vertical;
Row 1:
──────
version(): 22.8.1.2097
How to reproduce
See above.
Expected behavior
- base58Decode should produce correct output
- base58Decode/base58Encode pair should return original value
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
potential bugTo be reviewed by developers and confirmed/rejected.To be reviewed by developers and confirmed/rejected.