Fix T37826: Opening a new image in the image editor
Cast dimensions to size_t before multiplication. Also made add_ibuf_size survive cases when image buffer allocation failed.
This commit is contained in:
parent
a2543ee43d
commit
c193dbe30b
Notes:
blender-bot
2023-02-14 11:35:46 +01:00
Referenced by issue #37826, Opening a new image in the image editor.
|
@ -682,7 +682,6 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
|
|||
|
||||
if (floatbuf) {
|
||||
ibuf = IMB_allocImBuf(width, height, depth, IB_rectfloat);
|
||||
rect_float = ibuf->rect_float;
|
||||
|
||||
if (colorspace_settings->name[0] == '\0') {
|
||||
const char *colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_FLOAT);
|
||||
|
@ -690,11 +689,13 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
|
|||
BLI_strncpy(colorspace_settings->name, colorspace, sizeof(colorspace_settings->name));
|
||||
}
|
||||
|
||||
IMB_colormanagement_check_is_data(ibuf, colorspace_settings->name);
|
||||
if (ibuf != NULL) {
|
||||
rect_float = ibuf->rect_float;
|
||||
IMB_colormanagement_check_is_data(ibuf, colorspace_settings->name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ibuf = IMB_allocImBuf(width, height, depth, IB_rect);
|
||||
rect = (unsigned char *)ibuf->rect;
|
||||
|
||||
if (colorspace_settings->name[0] == '\0') {
|
||||
const char *colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE);
|
||||
|
@ -702,7 +703,14 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
|
|||
BLI_strncpy(colorspace_settings->name, colorspace, sizeof(colorspace_settings->name));
|
||||
}
|
||||
|
||||
IMB_colormanagement_assign_rect_colorspace(ibuf, colorspace_settings->name);
|
||||
if (ibuf != NULL) {
|
||||
rect = (unsigned char *)ibuf->rect;
|
||||
IMB_colormanagement_assign_rect_colorspace(ibuf, colorspace_settings->name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ibuf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
|
||||
|
|
|
@ -201,7 +201,7 @@ bool addzbufImBuf(ImBuf *ibuf)
|
|||
|
||||
IMB_freezbufImBuf(ibuf);
|
||||
|
||||
size = (size_t)(ibuf->x * ibuf->y) * sizeof(unsigned int);
|
||||
size = (size_t)ibuf->x * (size_t)ibuf->y * sizeof(unsigned int);
|
||||
|
||||
if ((ibuf->zbuf = MEM_mapallocN(size, __func__))) {
|
||||
ibuf->mall |= IB_zbuf;
|
||||
|
@ -220,7 +220,7 @@ bool addzbuffloatImBuf(ImBuf *ibuf)
|
|||
|
||||
IMB_freezbuffloatImBuf(ibuf);
|
||||
|
||||
size = (size_t)(ibuf->x * ibuf->y) * sizeof(float);
|
||||
size = (size_t)ibuf->x * (size_t)ibuf->y * sizeof(float);
|
||||
|
||||
if ((ibuf->zbuf_float = MEM_mapallocN(size, __func__))) {
|
||||
ibuf->mall |= IB_zbuffloat;
|
||||
|
@ -300,7 +300,7 @@ bool imb_addrectfloatImBuf(ImBuf *ibuf)
|
|||
if (ibuf->rect_float)
|
||||
imb_freerectfloatImBuf(ibuf); /* frees mipmap too, hrm */
|
||||
|
||||
size = (size_t)(ibuf->x * ibuf->y) * sizeof(float[4]);
|
||||
size = (size_t)ibuf->x * (size_t)ibuf->y * sizeof(float[4]);
|
||||
|
||||
ibuf->channels = 4;
|
||||
if ((ibuf->rect_float = MEM_mapallocN(size, __func__))) {
|
||||
|
@ -324,7 +324,7 @@ bool imb_addrectImBuf(ImBuf *ibuf)
|
|||
MEM_freeN(ibuf->rect);
|
||||
ibuf->rect = NULL;
|
||||
|
||||
size = (size_t)(ibuf->x * ibuf->y) * sizeof(unsigned int);
|
||||
size = (size_t)ibuf->x * (size_t)ibuf->y * sizeof(unsigned int);
|
||||
|
||||
if ((ibuf->rect = MEM_mapallocN(size, __func__))) {
|
||||
ibuf->mall |= IB_rect;
|
||||
|
|
Loading…
Reference in New Issue