-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
src: fix check for accepting Buffers into Node’s allocator #27174
Conversation
This condition was incorrect. We currently take the fallback path in default Node builds, which always works, but may come with some overhead, whereas the intention was that we use the fast path in this condition. This is causing issues for embedders, because we would erroneously try to take the fast path when they don’t provide a Node.js-style `ArrayBufferAlloactor`, and crash as a consequence of that. This also requires us to relax the check in the debugging ArrayBuffer allocator a bit, because since d117e41, 0-sized ArrayBuffers may actually point to allocations of size 1. Previously, that wasn’t caught because the fallback path circumvented our ArrayBufferAllocator. Refs: nodejs@84e02b1#r33116006
Always use the right allocator for memory that is turned into an `ArrayBuffer` at a later point. This enables embedders to use their own `ArrayBuffer::Allocator`s, and is inspired by Electron’s electron/node@f61bae3440e. It should render their downstream patch unnecessary. Refs: electron/node@f61bae3 PR-URL: #26207 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
BTW, is it possible to cctest this now? |
It would be, but our cctest helpers aren’t really written to accommodate this… |
@@ -138,7 +138,11 @@ void DebuggingArrayBufferAllocator::UnregisterPointerInternal(void* data, | |||
if (data == nullptr) return; | |||
auto it = allocations_.find(data); | |||
CHECK_NE(it, allocations_.end()); | |||
CHECK_EQ(it->second, size); | |||
if (size > 0) { |
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.
Would this be a good place to use CHECK_IMPLIES()
?
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.
@cjihrig Does it make a difference? If I want to say “this check is only valid under these conditions”, then I am okay with using an if
…
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.
It shouldn't make a difference. I just thought it might be a bit more concise and possibly (I'm not sure) simplify code coverage.
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.
Yeah, I’d prefer to keep this as it is here. I’ve noticed this because of failing tests, so I think code coverage isn’t an issue either.
Landed in 427fce7 |
This condition was incorrect. We currently take the fallback path in default Node builds, which always works, but may come with some overhead, whereas the intention was that we use the fast path in this condition. This is causing issues for embedders, because we would erroneously try to take the fast path when they don’t provide a Node.js-style `ArrayBufferAlloactor`, and crash as a consequence of that. This also requires us to relax the check in the debugging ArrayBuffer allocator a bit, because since d117e41, 0-sized ArrayBuffers may actually point to allocations of size 1. Previously, that wasn’t caught because the fallback path circumvented our ArrayBufferAllocator. Refs: 84e02b1#r33116006 PR-URL: #27174 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
This condition was incorrect. We currently take the fallback
path in default Node builds, which always works, but may come with
some overhead, whereas the intention was that we use the fast path
in this condition.
This is causing issues for embedders, because we would erroneously
try to take the fast path when they don’t provide a Node.js-style
ArrayBufferAlloactor
, and crash as a consequence of that.This also requires us to relax the check in the debugging ArrayBuffer
allocator a bit, because since d117e41, 0-sized ArrayBuffers
may actually point to allocations of size 1. Previously, that wasn’t
caught because the fallback path circumvented our ArrayBufferAllocator.
Refs: 84e02b1#r33116006
/cc @zcbenz
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes