-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Fix array and string trim_in_place allocation bounds check #2840
Conversation
|
Thanks for this one. The ci failure on aarch64 seems to not give any output for 10 minutes. Most likely a runtime shutdown error, but unrelated. |
I would restart the failed job but I don't have permissions to do that. |
Prior to this commit, if `Array.trim_in_place` and `String.trim_in place` trimmed all of the memory allocated for the array or string (i.e. `trim_point == space()`) then trim_in_place would still use _ptr._offset to set the pointer to be the byte after the last byte allocated by the array or string. This was bad for many reasons but sometimes especially bad if that next byte happened to be in a different pagemap that had not yet been allocated. This would result in a segfault the next time `reserve` was called because the runtime would think this pointer was not allocated by pony and complain that it cannot realloc memory not allocated by pony. This commit fixes the logic in trim_in_place to allocate a new Pointer if _alloc == 0 (i.e. all of the memory allocated for the array or string has been trimmed away). This ensures that the `_ptr` will never point to memory not owned/allocated by the array also guaranteeing no segfaults will occur due to unallocated pagemap references. This commit also modifies the `Array.trim_in_place` and `String.trim_in_place` tests to prevent a regression.
Grrrrr... Circle CI is very funny when you have your own fork set up to run tests and also open a PR for the same. I'm almost done with the |
The |
Prior to this commit, if
Array.trim_in_place
andString.trim_in place
trimmed all of the memory allocated for the array or string (i.e.
trim_point == space()
) then trim_in_place would still use _ptr._offsetto set the pointer to be the byte after the last byte allocated by the
array or string. This was bad for many reasons but sometimes especially
bad if that next byte happened to be in a different pagemap that had not
yet been allocated. This would result in a segfault the next time
reserve
was called because the runtime would think this pointer was not allocated
by pony and complain that it cannot realloc memory not allocated by pony.
This commit fixes the logic in trim_in_place to allocate a new Pointer
if _alloc == 0 (i.e. all of the memory allocated for the array or string
has been trimmed away). This ensures that the
_ptr
will never point tomemory not owned/allocated by the array also guaranteeing no segfaults
will occur due to unallocated pagemap references.
This commit also modifies the
Array.trim_in_place
andString.trim_in_place
tests to prevent a regression.