forked from len0rd/rockbox
Adjust AC decode such that decode *always* stops before storing an unneeded coefficient. Remove extra lines from zag[] as it should not be possible to store a coefficient for k>63, even for corrupted files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21283 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
02a53fd809
commit
e40075e5b7
1 changed files with 11 additions and 16 deletions
|
@ -1496,8 +1496,6 @@ static const unsigned char zag[] =
|
||||||
29, 22, 15, 23, 30, 37, 44, 51,
|
29, 22, 15, 23, 30, 37, 44, 51,
|
||||||
58, 59, 52, 45, 38, 31, 39, 46,
|
58, 59, 52, 45, 38, 31, 39, 46,
|
||||||
53, 60, 61, 54, 47, 55, 62, 63,
|
53, 60, 61, 54, 47, 55, 62, 63,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, /* extra entries in case k>63 below */
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* zig[i] is the the zig-zag order position of the i'th element of natural
|
/* zig[i] is the the zig-zag order position of the i'th element of natural
|
||||||
|
@ -1949,34 +1947,29 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
|
||||||
/* coefficient buffer must be cleared */
|
/* coefficient buffer must be cleared */
|
||||||
MEMSET(block+1, 0, p_jpeg->zero_need[!!ci] * sizeof(int));
|
MEMSET(block+1, 0, p_jpeg->zero_need[!!ci] * sizeof(int));
|
||||||
/* Section F.2.2.2: decode the AC coefficients */
|
/* Section F.2.2.2: decode the AC coefficients */
|
||||||
for (; k < p_jpeg->k_need[!!ci]; k++)
|
while(true)
|
||||||
{
|
{
|
||||||
huff_decode_ac(p_jpeg, actbl, s);
|
huff_decode_ac(p_jpeg, actbl, s);
|
||||||
r = s >> 4;
|
r = s >> 4;
|
||||||
s &= 15;
|
s &= 15;
|
||||||
|
k += r;
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
k += r;
|
|
||||||
check_bit_buffer(p_jpeg, s);
|
check_bit_buffer(p_jpeg, s);
|
||||||
|
if (k >= p_jpeg->k_need[!!ci])
|
||||||
|
goto skip_rest;
|
||||||
r = get_bits(p_jpeg, s);
|
r = get_bits(p_jpeg, s);
|
||||||
r = HUFF_EXTEND(r, s);
|
r = HUFF_EXTEND(r, s);
|
||||||
int a = zag[k];
|
r = MULTIPLY16(r, p_jpeg->quanttable[!!ci][k]);
|
||||||
if (a <= zag[p_jpeg->k_need[!!ci]] && (a & 7) <=
|
block[zag[k]] = r ;
|
||||||
(zag[p_jpeg->k_need[!!ci]] & 7))
|
|
||||||
{
|
|
||||||
r = MULTIPLY16(r, p_jpeg->quanttable[!!ci][k]);
|
|
||||||
block[zag[k]] = r ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (r != 15)
|
if (r != 15)
|
||||||
{
|
goto block_end;
|
||||||
k = 64;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
k += r;
|
|
||||||
}
|
}
|
||||||
|
if ((++k) & 64)
|
||||||
|
goto block_end;
|
||||||
} /* for k */
|
} /* for k */
|
||||||
}
|
}
|
||||||
for (; k < 64; k++)
|
for (; k < 64; k++)
|
||||||
|
@ -1989,6 +1982,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
|
||||||
{
|
{
|
||||||
k += r;
|
k += r;
|
||||||
check_bit_buffer(p_jpeg, s);
|
check_bit_buffer(p_jpeg, s);
|
||||||
|
skip_rest:
|
||||||
drop_bits(p_jpeg, s);
|
drop_bits(p_jpeg, s);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1998,6 +1992,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
|
||||||
k += r;
|
k += r;
|
||||||
}
|
}
|
||||||
} /* for k */
|
} /* for k */
|
||||||
|
block_end:
|
||||||
#ifndef HAVE_LCD_COLOR
|
#ifndef HAVE_LCD_COLOR
|
||||||
if (!ci)
|
if (!ci)
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue