|
@@ -1125,7 +1125,7 @@ static int stbi__mad3sizes_valid(int a, int b, int c, int add)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow
|
|
// returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow
|
|
|
-#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)
|
|
|
|
|
|
|
+#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM) || !defined(STBI_NO_PNG) || !defined(STBI_NO_PSD)
|
|
|
static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)
|
|
static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)
|
|
|
{
|
|
{
|
|
|
return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&
|
|
return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&
|
|
@@ -1148,7 +1148,7 @@ static void *stbi__malloc_mad3(int a, int b, int c, int add)
|
|
|
return stbi__malloc(a*b*c + add);
|
|
return stbi__malloc(a*b*c + add);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)
|
|
|
|
|
|
|
+#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM) || !defined(STBI_NO_PNG) || !defined(STBI_NO_PSD)
|
|
|
static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
|
|
static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
|
|
|
{
|
|
{
|
|
|
if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL;
|
|
if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL;
|
|
@@ -1306,7 +1306,7 @@ static stbi__uint16 *stbi__convert_8_to_16(stbi_uc *orig, int w, int h, int chan
|
|
|
int img_len = w * h * channels;
|
|
int img_len = w * h * channels;
|
|
|
stbi__uint16 *enlarged;
|
|
stbi__uint16 *enlarged;
|
|
|
|
|
|
|
|
- enlarged = (stbi__uint16 *) stbi__malloc(img_len*2);
|
|
|
|
|
|
|
+ enlarged = (stbi__uint16 *) stbi__malloc_mad2(img_len, 2, 0);
|
|
|
if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
|
|
if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
|
|
|
|
|
|
|
|
for (i = 0; i < img_len; ++i)
|
|
for (i = 0; i < img_len; ++i)
|
|
@@ -1975,7 +1975,7 @@ static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int r
|
|
|
if (req_comp == img_n) return data;
|
|
if (req_comp == img_n) return data;
|
|
|
STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
|
|
STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
|
|
|
|
|
|
|
|
- good = (stbi__uint16 *) stbi__malloc(req_comp * x * y * 2);
|
|
|
|
|
|
|
+ good = (stbi__uint16 *) stbi__malloc_mad4(req_comp, x, y, 2, 0);
|
|
|
if (good == NULL) {
|
|
if (good == NULL) {
|
|
|
STBI_FREE(data);
|
|
STBI_FREE(data);
|
|
|
return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
|
|
return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
|
|
@@ -5301,10 +5301,10 @@ static void stbi__de_iphone(stbi__png *z)
|
|
|
|
|
|
|
|
static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp, unsigned int *palette_buffer, int palette_buffer_len)
|
|
static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp, unsigned int *palette_buffer, int palette_buffer_len)
|
|
|
{
|
|
{
|
|
|
- stbi_uc _palette[1024], pal_img_n=0;
|
|
|
|
|
|
|
+ stbi_uc _palette[1024]={0}, pal_img_n=0;
|
|
|
stbi_uc *palette = _palette;
|
|
stbi_uc *palette = _palette;
|
|
|
stbi_uc has_trans=0, tc[3]={0};
|
|
stbi_uc has_trans=0, tc[3]={0};
|
|
|
- stbi__uint16 tc16[3];
|
|
|
|
|
|
|
+ stbi__uint16 tc16[3]={0};
|
|
|
stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0;
|
|
stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0;
|
|
|
int first=1,k,interlace=0, color=0, is_iphone=0;
|
|
int first=1,k,interlace=0, color=0, is_iphone=0;
|
|
|
stbi__context *s = z->s;
|
|
stbi__context *s = z->s;
|
|
@@ -7221,7 +7221,10 @@ static void *stbi__load_gif_main_outofmem(stbi__gif *g, stbi_uc *out, int **dela
|
|
|
STBI_FREE(g->background);
|
|
STBI_FREE(g->background);
|
|
|
|
|
|
|
|
if (out) STBI_FREE(out);
|
|
if (out) STBI_FREE(out);
|
|
|
- if (delays && *delays) STBI_FREE(*delays);
|
|
|
|
|
|
|
+ if (delays && *delays) {
|
|
|
|
|
+ STBI_FREE(*delays);
|
|
|
|
|
+ *delays = NULL;
|
|
|
|
|
+ }
|
|
|
return stbi__errpuc("outofmem", "Out of memory");
|
|
return stbi__errpuc("outofmem", "Out of memory");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -7256,19 +7259,15 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y,
|
|
|
stride = g.w * g.h * 4;
|
|
stride = g.w * g.h * 4;
|
|
|
|
|
|
|
|
if (out) {
|
|
if (out) {
|
|
|
- void *tmp = (stbi_uc*) STBI_REALLOC_SIZED( out, out_size, layers * stride );
|
|
|
|
|
- if (!tmp)
|
|
|
|
|
|
|
+ out = (stbi_uc*) STBI_REALLOC_SIZED( out, out_size, layers * stride );
|
|
|
|
|
+ if (!out)
|
|
|
return stbi__load_gif_main_outofmem(&g, out, delays);
|
|
return stbi__load_gif_main_outofmem(&g, out, delays);
|
|
|
- else {
|
|
|
|
|
- out = (stbi_uc*) tmp;
|
|
|
|
|
- out_size = layers * stride;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ out_size = layers * stride;
|
|
|
|
|
|
|
|
if (delays) {
|
|
if (delays) {
|
|
|
- int *new_delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers );
|
|
|
|
|
- if (!new_delays)
|
|
|
|
|
|
|
+ *delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers );
|
|
|
|
|
+ if (!*delays)
|
|
|
return stbi__load_gif_main_outofmem(&g, out, delays);
|
|
return stbi__load_gif_main_outofmem(&g, out, delays);
|
|
|
- *delays = new_delays;
|
|
|
|
|
delays_size = layers * sizeof(int);
|
|
delays_size = layers * sizeof(int);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|