Skip to content

Fixed crash when decrypting bogus input#40168

Closed
Enmk wants to merge 1 commit intoClickHouse:masterfrom
Enmk:fixed_Nullable_getDataAt_and_decrypt
Closed

Fixed crash when decrypting bogus input#40168
Enmk wants to merge 1 commit intoClickHouse:masterfrom
Enmk:fixed_Nullable_getDataAt_and_decrypt

Conversation

@Enmk
Copy link
Copy Markdown
Contributor

@Enmk Enmk commented Aug 12, 2022

Changelog category

  • Bug Fix

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Do not allow anything but String or FixedString as ciphertext parameter of decrypt.
...

Closes: #39987

Some assumptions of ColumnArray::getDataAt() were broken by ColumnNullable::getDataAt().
Also made sure that users call decrypt only on String or FixedString
@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label Aug 12, 2022
*/
StringRef getDataAt(size_t n) const override
{
auto nestedData = getNestedColumn().getDataAt(n);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong style.

if (isNullAt(n))
return EMPTY_STRING_REF;
{
// data for NULL-items must have valid data pointer, otherwise some assumtions down the road are broken.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is unclear.

{
auto nestedData = getNestedColumn().getDataAt(n);
if (isNullAt(n))
return EMPTY_STRING_REF;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EMPTY_STRING_REF is unneeded and should be wiped from the codebase entirely.

FunctionArgumentDescriptors{
{"mode", &isStringOrFixedString<IDataType>, isColumnConst, "decryption mode string"},
{"input", nullptr, nullptr, "ciphertext"},
{"input", &isStringOrFixedString<IDataType>, nullptr, "ciphertext"},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the validator for the third argument remains "nullptr"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't impose any limitations on column type, it can be either const, nullable or regular.

UInt64 index = 0;

if (elem != EMPTY_STRING_REF)
if (elem.size == 0 && col_arg_cloned->isNullAt(0))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this branch of code should actually check?

SELECT decrypt('aes-128-ecb', 'text', 'key', 'IV', 1213); --{serverError 43} bad AAD type
SELECT decrypt('aes-128-gcm', 'text', 'key', 'IV', 1213); --{serverError 43} bad AAD type

-- Invalid ciphertext type
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a new test instead of editing the old test.

Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@alexey-milovidov alexey-milovidov self-assigned this Aug 12, 2022
auto nestedData = getNestedColumn().getDataAt(n);
if (isNullAt(n))
return EMPTY_STRING_REF;
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this branch can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we'll get non-zero size StringRef. E.g. 4 for UInt32, and IMO that would lead to matching hashes for UInt32(0) and null item, which might break something else.

@alexey-milovidov
Copy link
Copy Markdown
Member

Tests have failed.

@alexey-milovidov
Copy link
Copy Markdown
Member

Superseded by #40194.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FunctionDecrypt: Too large size ... passed to allocator. It indicates an error

3 participants