Skip to content

Commit 5609fcf

Browse files
committed
limit 1
1 parent 0b3f1c8 commit 5609fcf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/ImageData.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)