Skip to content

Stop managed_array from accidentally changing C++ types#155

Open
willvale wants to merge 3 commits into
JBenda:masterfrom
willvale:fix-cpp-type-transmutation
Open

Stop managed_array from accidentally changing C++ types#155
willvale wants to merge 3 commits into
JBenda:masterfrom
willvale:fix-cpp-type-transmutation

Conversation

@willvale

Copy link
Copy Markdown
Contributor

Storing non-POD types in char buffers is unsafe.

  • Ensure alignments are compatible with desired type.
  • Ensure raw data is copied with memcpy

Otherwise, _list_handouts placement-constructs entries as one type (list_impl) which is changed when they're copied by the copy constructor of T (list_interface, different type). For POD data this wouldn't matter, but here it changes the vtable pointer and indirectly causes an OOB write.

This crashed my memory allocator, which is how I spotted it.

willvale added 3 commits June 29, 2026 23:06
Storing non-POD types in char buffers is unsafe.

* Ensure alignments are compatible with desired type.
* Ensure raw data is copied with memcpy

Otherwise, the list entries are created raw and placement-constructed as one type, which is changed when they're copied by the copy constructor of T (different type). For POD data this wouldn't matter, but here it changes the vtable pointer and indirectly causes an OOB write.
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.

1 participant