-
Notifications
You must be signed in to change notification settings - Fork 199
Fix UB in ColumnStringBlock::AppendUnsafe when appending empty string_view #489
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?
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -136,8 +136,13 @@ struct ColumnString::Block | |||||||||
| std::string_view AppendUnsafe(std::string_view str) { | ||||||||||
| const auto pos = &data_[size]; | ||||||||||
|
|
||||||||||
| memcpy(pos, str.data(), str.size()); | ||||||||||
| size += str.size(); | ||||||||||
| // memcpy's source pointer is declared nonnull regardless of the | ||||||||||
| // size argument, so an empty string_view backed by std::string() | ||||||||||
| // (where data() may be null) trips UBSan on every empty append. | ||||||||||
|
Comment on lines
+140
to
+141
|
||||||||||
| // size argument, so an empty string_view backed by std::string() | |
| // (where data() may be null) trips UBSan on every empty append. | |
| // size argument, so an empty string_view with a null data() pointer | |
| // trips UBSan on every empty append. |
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.
const auto pos = &data_[size];can be undefined behavior whensize == capacity(e.g., appending an empty string when the block is full, or whencapacity==0), becausedata_[size]conceptually dereferences one-past-the-end. Prefer computing the pointer viadata_.get() + size(and consider applying the same change in the otherBlockhelpers that use&data_[size]), so zero-length operations don’t rely on out-of-boundsoperator[]evaluation.