-
Notifications
You must be signed in to change notification settings - Fork 4.1k
MINOR: [C++][Parquet] Reject too-short statistics values in FormatStatValue #50025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,43 @@ std::string FormatFloat16Value(::std::string_view val) { | |
|
|
||
| std::string FormatStatValue(Type::type parquet_type, ::std::string_view val, | ||
| const std::shared_ptr<const LogicalType>& logical_type) { | ||
| // Statistics blobs come from the file's Thrift-encoded metadata and may have | ||
| // arbitrary length under a malicious writer. Reject any value that is shorter | ||
| // than what the physical (and, for FLOAT16, logical) type requires so the | ||
| // memcpy/byte loads below cannot run past the buffer. | ||
| size_t required = 0; | ||
| switch (parquet_type) { | ||
| case Type::BOOLEAN: | ||
| required = sizeof(bool); | ||
| break; | ||
| case Type::INT32: | ||
| case Type::FLOAT: | ||
| required = 4; | ||
| break; | ||
| case Type::INT64: | ||
| case Type::DOUBLE: | ||
| required = 8; | ||
| break; | ||
| case Type::INT96: | ||
| required = 3 * sizeof(int32_t); | ||
| break; | ||
| case Type::BYTE_ARRAY: | ||
| case Type::FIXED_LEN_BYTE_ARRAY: | ||
| if (logical_type != nullptr && logical_type->is_float16()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not dealing with the length of |
||
| required = 2; | ||
| } | ||
| break; | ||
| case Type::UNDEFINED: | ||
| default: | ||
| break; | ||
| } | ||
| if (val.size() < required) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little hesitant to complicate |
||
| std::stringstream ss; | ||
| ss << "Statistics value of " << val.size() << " bytes is too small for " | ||
| << TypeToString(parquet_type); | ||
| throw ParquetException(ss.str()); | ||
| } | ||
|
|
||
| std::stringstream result; | ||
| const char* bytes = val.data(); | ||
| switch (parquet_type) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to put
BYTE_ARRAYandUNDEFINEDtogether since they are skipped. In case you don't know,BYTE_ARRAYcannot havefloat16logical type.