Fix crash when converting invalid image to JPEG

This commit is contained in:
Cheng Zhao 2017-07-31 15:48:54 +09:00
parent a6c8329a68
commit 6ee95f9529

View file

@ -291,6 +291,8 @@ v8::Local<v8::Value> NativeImage::ToBitmap(mate::Arguments* args) {
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
std::vector<unsigned char> output;
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
if (output.empty())
return node::Buffer::New(isolate, 0).ToLocalChecked();
return node::Buffer::Copy(
isolate,
reinterpret_cast<const char*>(&output.front()),