-
Notifications
You must be signed in to change notification settings - Fork 30k
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
buffer: throw exception when creating from non-Node.js Context #23938
Conversation
Throw an exception instead of crashing when attempting to create `Buffer` objects from a Context that is not associated with a Node.js `Environment`. Possible alternatives for the future might be just returning a plain `Uint8Array`, or working on providing `Buffer` for all `Context`s.
Throw an exception instead of crashing when attempting to create `Buffer` objects from a Context that is not associated with a Node.js `Environment`. Possible alternatives for the future might be just returning a plain `Uint8Array`, or working on providing `Buffer` for all `Context`s. PR-URL: nodejs#23938 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Landed in 9c7d191 (with @vsemozhetbyt's an/a nit). |
Throw an exception instead of crashing when attempting to create `Buffer` objects from a Context that is not associated with a Node.js `Environment`. Possible alternatives for the future might be just returning a plain `Uint8Array`, or working on providing `Buffer` for all `Context`s. PR-URL: #23938 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
@addaleax do you think this should be backported to |
@codebytere It might be nice to backport it in order to avoid conflicts, but it’s not super important. It sounds like maybe another commit should be backported first? Can you show the compilation error, that might help identify it? |
@addaleax so the throw helper initially took a ptr to an Environment, and was later changed to take an isolate; if i change the commit such that we have |
@codebytere I’ll try to backport #23879 (tomorrow), I think this sounds like that would solve the issue? :) |
i think so! thanks @addaleax ✨ |
@@ -364,7 +370,11 @@ MaybeLocal<Object> New(Isolate* isolate, | |||
void* hint) { | |||
EscapableHandleScope handle_scope(isolate); | |||
Environment* env = Environment::GetCurrent(isolate); | |||
CHECK_NOT_NULL(env); // TODO(addaleax): Handle nullptr here. | |||
if (env == nullptr) { | |||
callback(data, hint); |
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.
Belated review: this callback()
call and the free()
call on line 417 look a bit incongruent because they're not executed when the Buffer::New()
calls below them fail.
Performing the action only sometimes is confusing, IMO. A caller that diligently checks the return value and frees the memory when it's empty will now (sometimes) double-free.
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.
@bnoordhuis I think it was more or less the idea to be more consistent here and always take ownership, because in other cases we already did free the data when failing (e.g. in the New(Isolate*, Local<String>, encoding)
variant)…
Throw an exception instead of crashing when attempting to create `Buffer` objects from a Context that is not associated with a Node.js `Environment`. Possible alternatives for the future might be just returning a plain `Uint8Array`, or working on providing `Buffer` for all `Context`s. PR-URL: nodejs/node#23938 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Throw an exception instead of crashing when attempting to create
Buffer
objects from a Context that is not associated witha Node.js
Environment
.Possible alternatives for the future might be just returning
a plain
Uint8Array
, or working on providingBuffer
for allContext
s.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes