Skip to content

Avoid unsafe intermediate slice construction in varlena functions - #2368

Open
SergeiPatiakin wants to merge 1 commit into
pgcentralfoundation:developfrom
SergeiPatiakin:varlena-unsafe-slice
Open

Avoid unsafe intermediate slice construction in varlena functions#2368
SergeiPatiakin wants to merge 1 commit into
pgcentralfoundation:developfrom
SergeiPatiakin:varlena-unsafe-slice

Conversation

@SergeiPatiakin

Copy link
Copy Markdown
Contributor

unsafe __IncompleteArrayField<T>::as_slice calls unsafe ::core::slice::from_raw_parts, which is UB if the slice memory range is invalid.

But the length we pass in the varlena_4b* cases is varsize_1b(ptr) which is a garbage value
potentially larger than the real length. Therefore the slice memory range can indeed be invalid.

I don't think this is a practical concern today because we immediately do .as_ptr on
the intermediate slice, but still looks like technically UB.

@0xPoe 0xPoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Although it doesn’t cause any issues now, it’s reasonable to fix it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants