|
|
|
@ -1985,9 +1985,12 @@ static int stbi__build_huffman(stbi__huffman *h, int *count) |
|
|
|
|
int i,j,k=0; |
|
|
|
|
unsigned int code; |
|
|
|
|
// build size list for each symbol (from JPEG spec)
|
|
|
|
|
for (i=0; i < 16; ++i) |
|
|
|
|
for (j=0; j < count[i]; ++j) |
|
|
|
|
for (i=0; i < 16; ++i) { |
|
|
|
|
for (j=0; j < count[i]; ++j) { |
|
|
|
|
h->size[k++] = (stbi_uc) (i+1); |
|
|
|
|
if(k >= 257) return stbi__err("bad size list","Corrupt JPEG"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
h->size[k] = 0; |
|
|
|
|
|
|
|
|
|
// compute actual symbols (from jpeg spec)
|
|
|
|
@ -2112,6 +2115,8 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h) |
|
|
|
|
|
|
|
|
|
// convert the huffman code to the symbol id
|
|
|
|
|
c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k]; |
|
|
|
|
if(c < 0 || c >= 256) // symbol id out of bounds!
|
|
|
|
|
return -1; |
|
|
|
|
STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) == h->code[c]); |
|
|
|
|
|
|
|
|
|
// convert the id to a symbol
|
|
|
|
@ -3103,6 +3108,7 @@ static int stbi__process_marker(stbi__jpeg *z, int m) |
|
|
|
|
sizes[i] = stbi__get8(z->s); |
|
|
|
|
n += sizes[i]; |
|
|
|
|
} |
|
|
|
|
if(n > 256) return stbi__err("bad DHT header","Corrupt JPEG"); // Loop over i < n would write past end of values!
|
|
|
|
|
L -= 17; |
|
|
|
|
if (tc == 0) { |
|
|
|
|
if (!stbi__build_huffman(z->huff_dc+th, sizes)) return 0; |
|
|
|
|