Fix potential UB when list() aggregate is used in combination with other arena using aggregate functions
#11306
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a ubsan issue I encountered when constructing some gnarly sql to output function documentation into a large nested structure for further processing. Even though the list segment code tries it best to ensure any allocations it makes are aligned by rounding up, if the shared aggregate arena is used by other aggregate functions this alignment can get out of sync.
This PR adds a
AlignNext()helper function to theArenaAllocatorwhich moves the current position in the head chunk forwards until it is a multiple of 8 (if required), additionally I've also changed theAllocateAlignedandReallocateAlignedto call this function before allocating anything to to ensure the next allocation actually will be aligned regardless of how the state of the allocator is left from previously performed allocations.