summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2009-06-14 01:19:16 +0000
committerAndrew Mahone <andrew.mahone@gmail.com>2009-06-14 01:19:16 +0000
commite40075e5b74c69f7a5358e65d3b997dcd2649cfc (patch)
treecb52f36b0be1928dd38e6b2a6873b091b2694b04 /apps
parent02a53fd809b46ef60555c55d550e6754c46c4c69 (diff)
downloadrockbox-e40075e5b74c69f7a5358e65d3b997dcd2649cfc.zip
rockbox-e40075e5b74c69f7a5358e65d3b997dcd2649cfc.tar.gz
rockbox-e40075e5b74c69f7a5358e65d3b997dcd2649cfc.tar.bz2
rockbox-e40075e5b74c69f7a5358e65d3b997dcd2649cfc.tar.xz
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
Diffstat (limited to 'apps')
-rw-r--r--apps/recorder/jpeg_load.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/apps/recorder/jpeg_load.c b/apps/recorder/jpeg_load.c
index 9115ee2..c4de7c2 100644
--- a/apps/recorder/jpeg_load.c
+++ b/apps/recorder/jpeg_load.c
@@ -1496,8 +1496,6 @@ static const unsigned char zag[] =
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
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
@@ -1949,34 +1947,29 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
/* coefficient buffer must be cleared */
MEMSET(block+1, 0, p_jpeg->zero_need[!!ci] * sizeof(int));
/* 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);
r = s >> 4;
s &= 15;
+ k += r;
if (s)
{
- k += r;
check_bit_buffer(p_jpeg, s);
+ if (k >= p_jpeg->k_need[!!ci])
+ goto skip_rest;
r = get_bits(p_jpeg, s);
r = HUFF_EXTEND(r, s);
- int a = zag[k];
- if (a <= zag[p_jpeg->k_need[!!ci]] && (a & 7) <=
- (zag[p_jpeg->k_need[!!ci]] & 7))
- {
- r = MULTIPLY16(r, p_jpeg->quanttable[!!ci][k]);
- block[zag[k]] = r ;
- }
+ r = MULTIPLY16(r, p_jpeg->quanttable[!!ci][k]);
+ block[zag[k]] = r ;
}
else
{
if (r != 15)
- {
- k = 64;
- break;
- }
- k += r;
+ goto block_end;
}
+ if ((++k) & 64)
+ goto block_end;
} /* for k */
}
for (; k < 64; k++)
@@ -1989,6 +1982,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
{
k += r;
check_bit_buffer(p_jpeg, s);
+skip_rest:
drop_bits(p_jpeg, s);
}
else
@@ -1998,6 +1992,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
k += r;
}
} /* for k */
+block_end:
#ifndef HAVE_LCD_COLOR
if (!ci)
#endif