|
|
|
@ -640,7 +640,7 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1]; |
|
|
|
|
|
|
|
|
|
#ifndef STBI_MALLOC |
|
|
|
|
#define STBI_MALLOC(sz) malloc(sz) |
|
|
|
|
#define STBI_REALLOC(p,sz) realloc(p,sz) |
|
|
|
|
#define STBI_REALLOC(p,oldsz,newsz) realloc(p,newsz) |
|
|
|
|
#define STBI_FREE(p) free(p) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
@ -3616,14 +3616,14 @@ stbi_inline static int stbi__zhuffman_decode(stbi__zbuf *a, stbi__zhuffman *z) |
|
|
|
|
static int stbi__zexpand(stbi__zbuf *z, char *zout, int n) // need to make room for n bytes
|
|
|
|
|
{ |
|
|
|
|
char *q; |
|
|
|
|
int cur, limit; |
|
|
|
|
int cur, limit, old_limit; |
|
|
|
|
z->zout = zout; |
|
|
|
|
if (!z->z_expandable) return stbi__err("output buffer limit","Corrupt PNG"); |
|
|
|
|
cur = (int) (z->zout - z->zout_start); |
|
|
|
|
limit = (int) (z->zout_end - z->zout_start); |
|
|
|
|
limit = old_limit = (int) (z->zout_end - z->zout_start); |
|
|
|
|
while (cur + n > limit) |
|
|
|
|
limit *= 2; |
|
|
|
|
q = (char *) STBI_REALLOC(z->zout_start, limit); |
|
|
|
|
q = (char *) STBI_REALLOC(z->zout_start, old_limit, limit); |
|
|
|
|
if (q == NULL) return stbi__err("outofmem", "Out of memory"); |
|
|
|
|
z->zout_start = q; |
|
|
|
|
z->zout = q + cur; |
|
|
|
@ -4408,11 +4408,12 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) |
|
|
|
|
if (scan == STBI__SCAN_header) { s->img_n = pal_img_n; return 1; } |
|
|
|
|
if ((int)(ioff + c.length) < (int)ioff) return 0; |
|
|
|
|
if (ioff + c.length > idata_limit) { |
|
|
|
|
stbi__uint32 idata_limit_old = idata_limit; |
|
|
|
|
stbi_uc *p; |
|
|
|
|
if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096; |
|
|
|
|
while (ioff + c.length > idata_limit) |
|
|
|
|
idata_limit *= 2; |
|
|
|
|
p = (stbi_uc *) STBI_REALLOC(z->idata, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); |
|
|
|
|
p = (stbi_uc *) STBI_REALLOC(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory"); |
|
|
|
|
z->idata = p; |
|
|
|
|
} |
|
|
|
|
if (!stbi__getn(s, z->idata+ioff,c.length)) return stbi__err("outofdata","Corrupt PNG"); |
|
|
|
|