-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[fix](be) Bound BitmapValue::deserialize to prevent heap over-read on tampered BITMAP payloads #63702
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: master
Are you sure you want to change the base?
[fix](be) Bound BitmapValue::deserialize to prevent heap over-read on tampered BITMAP payloads #63702
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 |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ | |
| #include <utility> | ||
|
|
||
| #include "agent/be_exec_version_manager.h" | ||
| #include "common/exception.h" | ||
| #include "common/status.h" | ||
| #include "core/assert_cast.h" | ||
| #include "core/column/column.h" | ||
| #include "core/column/column_complex.h" | ||
|
|
@@ -90,8 +92,11 @@ const char* DataTypeBitMap::deserialize(const char* buf, MutableColumnPtr* colum | |
| const auto* meta_ptr = reinterpret_cast<const size_t*>(buf); | ||
| const char* data_ptr = buf + sizeof(size_t) * real_have_saved_num; | ||
| for (size_t i = 0; i < real_have_saved_num; ++i) { | ||
| data[i].deserialize(data_ptr); | ||
| data_ptr += unaligned_load<size_t>(&meta_ptr[i]); | ||
| auto one_size = unaligned_load<size_t>(&meta_ptr[i]); | ||
| if (!data[i].deserialize(data_ptr, one_size)) { | ||
| throw Exception(Status::DataQualityError("Failed to deserialize bitmap data")); | ||
| } | ||
| data_ptr += one_size; | ||
|
Contributor
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.
|
||
| } | ||
| return data_ptr; | ||
| } | ||
|
|
@@ -115,6 +120,8 @@ void DataTypeBitMap::serialize_as_stream(const BitmapValue& cvalue, BufferWritab | |
| void DataTypeBitMap::deserialize_as_stream(BitmapValue& value, BufferReadable& buf) { | ||
| StringRef ref; | ||
| buf.read_binary(ref); | ||
| value.deserialize(ref.data); | ||
| if (!value.deserialize(ref.data, ref.size)) { | ||
| throw Exception(Status::DataQualityError("Failed to deserialize bitmap data")); | ||
| } | ||
| } | ||
| } // namespace doris | ||
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.
This newly bounded decode can fail, but
insert_binary_datahas already inserted a default value and then ignores thefalsereturn. A malformed bitmap binary cell will therefore stay in the column as an empty/default bitmap rather than making the load/read fail, which violates the hardening goal and can silently corrupt query results. Please check the return value and throw/propagate an error before leaving the inserted value in place.