File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ ImageData::ImageData(const Napi::CallbackInfo& info) : Napi::ObjectWrap<ImageDat
3030 Napi::TypedArray dataArray;
3131 uint32_t width;
3232 uint32_t height;
33- int length;
33+ size_t length;
3434
3535 if (info[0 ].IsNumber () && info[1 ].IsNumber ()) {
3636 width = info[0 ].As <Napi::Number>().Uint32Value ();
@@ -43,6 +43,11 @@ ImageData::ImageData(const Napi::CallbackInfo& info) : Napi::ObjectWrap<ImageDat
4343 Napi::RangeError::New (env, " The source height is zero." ).ThrowAsJavaScriptException ();
4444 return ;
4545 }
46+ if (static_cast <uint64_t >(width) * height > INT32_MAX / 4 ) {
47+ std::string msg = " buffer exceeds " + std::to_string (INT32_MAX) + " bytes" ;
48+ Napi::Error::New (env, msg).ThrowAsJavaScriptException ();
49+ return ;
50+ }
4651 length = width * height * 4 ; // ImageData(w, h) constructor assumes 4 BPP; documented.
4752
4853 dataArray = Napi::Uint8Array::New (env, length, napi_uint8_clamped_array);
You can’t perform that action at this time.
0 commit comments