diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-09-10 04:53:39 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-09-10 04:53:39 +0400 |
commit | ec388a2a15346bace87cccc7e4da0eff89014ebb (patch) | |
tree | 76ed99e9746ab9d9ab4b32c7c36281b205386742 /source/blender/imbuf/intern | |
parent | 04316efc4a41a2d0427305b2655a8698713301a3 (diff) |
fix [#36187] Crash loading large images
alloc size was larger then an int, use size_t for all image alloc sizes.
Diffstat (limited to 'source/blender/imbuf/intern')
-rw-r--r-- | source/blender/imbuf/intern/allocimbuf.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index ca0b26fa4b7..8593b785096 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -193,14 +193,15 @@ ImBuf *IMB_makeSingleUser(ImBuf *ibuf) short addzbufImBuf(ImBuf *ibuf) { - int size; + size_t size; if (ibuf == NULL) return FALSE; IMB_freezbufImBuf(ibuf); - size = ibuf->x * ibuf->y * sizeof(unsigned int); - if ((ibuf->zbuf = MEM_mapallocN(size, "addzbufImBuf"))) { + size = (size_t)(ibuf->x * ibuf->y) * sizeof(unsigned int); + + if ((ibuf->zbuf = MEM_mapallocN(size, __func__))) { ibuf->mall |= IB_zbuf; ibuf->flags |= IB_zbuf; return TRUE; @@ -211,14 +212,15 @@ short addzbufImBuf(ImBuf *ibuf) short addzbuffloatImBuf(ImBuf *ibuf) { - int size; + size_t size; if (ibuf == NULL) return FALSE; IMB_freezbuffloatImBuf(ibuf); - size = ibuf->x * ibuf->y * sizeof(float); - if ((ibuf->zbuf_float = MEM_mapallocN(size, "addzbuffloatImBuf"))) { + size = (size_t)(ibuf->x * ibuf->y) * sizeof(float); + + if ((ibuf->zbuf_float = MEM_mapallocN(size, __func__))) { ibuf->mall |= IB_zbuffloat; ibuf->flags |= IB_zbuffloat; return TRUE; @@ -289,18 +291,17 @@ short imb_enlargeencodedbufferImBuf(ImBuf *ibuf) short imb_addrectfloatImBuf(ImBuf *ibuf) { - int size; + size_t size; if (ibuf == NULL) return FALSE; if (ibuf->rect_float) imb_freerectfloatImBuf(ibuf); /* frees mipmap too, hrm */ - size = ibuf->x * ibuf->y; - size = size * 4 * sizeof(float); + size = (size_t)(ibuf->x * ibuf->y) * sizeof(float[4]); + ibuf->channels = 4; - - if ((ibuf->rect_float = MEM_mapallocN(size, "imb_addrectfloatImBuf"))) { + if ((ibuf->rect_float = MEM_mapallocN(size, __func__))) { ibuf->mall |= IB_rectfloat; ibuf->flags |= IB_rectfloat; return TRUE; @@ -312,7 +313,7 @@ short imb_addrectfloatImBuf(ImBuf *ibuf) /* question; why also add zbuf? */ short imb_addrectImBuf(ImBuf *ibuf) { - int size; + size_t size; if (ibuf == NULL) return FALSE; @@ -321,10 +322,9 @@ short imb_addrectImBuf(ImBuf *ibuf) MEM_freeN(ibuf->rect); ibuf->rect = NULL; - size = ibuf->x * ibuf->y; - size = size * sizeof(unsigned int); + size = (size_t)(ibuf->x * ibuf->y) * sizeof(unsigned int); - if ((ibuf->rect = MEM_mapallocN(size, "imb_addrectImBuf"))) { + if ((ibuf->rect = MEM_mapallocN(size, __func__))) { ibuf->mall |= IB_rect; ibuf->flags |= IB_rect; if (ibuf->planes > 32) return (addzbufImBuf(ibuf)); |