diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-12-16 14:42:48 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-12-16 14:51:27 +0400 |
commit | c193dbe30b40beb435d6edde7117469f4706f98e (patch) | |
tree | 8df263e9d706f9a8f47d9b0210597d6ad33c22e4 /source | |
parent | a2543ee43dc6a35b36a8feda83679bf3e22e218d (diff) |
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.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 16 | ||||
-rw-r--r-- | source/blender/imbuf/intern/allocimbuf.c | 8 |
2 files changed, 16 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 41b2b1d80a1..40149c66358 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -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)); diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index 73d28cd4304..d7ca381bae6 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -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; |