Skip to content
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: don't crash when nativeImage.createFromBuffer() is called with invalid buffer #17344

Merged
merged 1 commit into from Mar 13, 2019

Conversation

miniak
Copy link
Contributor

@miniak miniak commented Mar 11, 2019

Description of Change

Adds missing node::Buffer::HasInstance(buffer) check before using the buffer.

Checklist

Release Notes

Notes: Fixed crash when nativeImage.createFromBuffer() is called with invalid buffer.

@miniak miniak self-assigned this Mar 11, 2019
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Mar 11, 2019
@miniak miniak changed the title fix: don't crash when nativeImage.createFromBuffer() called with invalid buffer fix: don't crash when nativeImage.createFromBuffer() is called with invalid buffer Mar 11, 2019
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more idiomatic way of saying "get the first argument as a buffer"? I see e.g. https://github.com/electron/electron/blob/master/atom/common/native_mate_converters/v8_value_converter.cc#L245

@miniak
Copy link
Contributor Author

miniak commented Mar 12, 2019

@nornagon I've seen this in other APIs to validate if an instance is a Buffer

void Clipboard::WriteBuffer(const std::string& format,
                            const v8::Local<v8::Value> buffer,
                            mate::Arguments* args) {
  if (!node::Buffer::HasInstance(buffer)) {
    args->ThrowError("buffer must be a node Buffer");
    return;
  }
...
}

An abstraction could be created, but we have to make sure it does not copy the data unnecessarily.

@miniak miniak force-pushed the miniak/fix-create-from-buffer branch from 670deda to 1b46d2e Compare March 12, 2019 07:46
@miniak
Copy link
Contributor Author

miniak commented Mar 12, 2019

@nornagon gsl::span<gsl::byte> would be a perfect abstraction for the Buffer data/size that can be parsed by mate converters. see https://github.com/Microsoft/GSL.

gsl::not_null<T> is also a nice (zero overhead in release mode) abstraction.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Mar 12, 2019
@codebytere codebytere merged commit df7dc93 into master Mar 13, 2019
@release-clerk
Copy link

release-clerk bot commented Mar 13, 2019

Release Notes Persisted

Fixed crash when nativeImage.createFromBuffer() is called with invalid buffer.

@trop
Copy link
Contributor

trop bot commented Mar 13, 2019

I have automatically backported this PR to "3-1-x", please check out #17372

@trop
Copy link
Contributor

trop bot commented Mar 13, 2019

I have automatically backported this PR to "4-0-x", please check out #17373

@trop
Copy link
Contributor

trop bot commented Mar 13, 2019

I have automatically backported this PR to "5-0-x", please check out #17374

@sofianguy sofianguy added this to Fixed in 5.0.0-beta.6 in 5.0.x Mar 20, 2019
@sofianguy sofianguy added this to Fixed (3.1.7) in 3.0.x / 3.1.x Mar 25, 2019
@sofianguy sofianguy added this to Fixed in 3.1.7 in 3.1.x Mar 29, 2019
kiku-jw pushed a commit to kiku-jw/electron that referenced this pull request May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
3.0.x / 3.1.x
Fixed (3.1.7)
3.1.x
Fixed in 3.1.7
5.0.x
Fixed in 5.0.0-beta.6
Development

Successfully merging this pull request may close these issues.

None yet

5 participants