summaryrefslogtreecommitdiff
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
parent02a53fd809b46ef60555c55d550e6754c46c4c69 (diff)
downloadrockbox-e40075e5b74c69f7a5358e65d3b997dcd2649cfc.tar.gz
rockbox-e40075e5b74c69f7a5358e65d3b997dcd2649cfc.zip
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
-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 9115ee23fb..c4de7c2004 100644
--- a/apps/recorder/jpeg_load.c
+++ b/apps/recorder/jpeg_load.c
@@ -1496,8 +1496,6 @@ static const unsigned char zag[] =
1496 29, 22, 15, 23, 30, 37, 44, 51, 1496 29, 22, 15, 23, 30, 37, 44, 51,
1497 58, 59, 52, 45, 38, 31, 39, 46, 1497 58, 59, 52, 45, 38, 31, 39, 46,
1498 53, 60, 61, 54, 47, 55, 62, 63, 1498 53, 60, 61, 54, 47, 55, 62, 63,
1499 0, 0, 0, 0, 0, 0, 0, 0, /* extra entries in case k>63 below */
1500 0, 0, 0, 0, 0, 0, 0, 0
1501}; 1499};
1502 1500
1503/* zig[i] is the the zig-zag order position of the i'th element of natural 1501/* 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)
1949 /* coefficient buffer must be cleared */ 1947 /* coefficient buffer must be cleared */
1950 MEMSET(block+1, 0, p_jpeg->zero_need[!!ci] * sizeof(int)); 1948 MEMSET(block+1, 0, p_jpeg->zero_need[!!ci] * sizeof(int));
1951 /* Section F.2.2.2: decode the AC coefficients */ 1949 /* Section F.2.2.2: decode the AC coefficients */
1952 for (; k < p_jpeg->k_need[!!ci]; k++) 1950 while(true)
1953 { 1951 {
1954 huff_decode_ac(p_jpeg, actbl, s); 1952 huff_decode_ac(p_jpeg, actbl, s);
1955 r = s >> 4; 1953 r = s >> 4;
1956 s &= 15; 1954 s &= 15;
1955 k += r;
1957 if (s) 1956 if (s)
1958 { 1957 {
1959 k += r;
1960 check_bit_buffer(p_jpeg, s); 1958 check_bit_buffer(p_jpeg, s);
1959 if (k >= p_jpeg->k_need[!!ci])
1960 goto skip_rest;
1961 r = get_bits(p_jpeg, s); 1961 r = get_bits(p_jpeg, s);
1962 r = HUFF_EXTEND(r, s); 1962 r = HUFF_EXTEND(r, s);
1963 int a = zag[k]; 1963 r = MULTIPLY16(r, p_jpeg->quanttable[!!ci][k]);
1964 if (a <= zag[p_jpeg->k_need[!!ci]] && (a & 7) <= 1964 block[zag[k]] = r ;
1965 (zag[p_jpeg->k_need[!!ci]] & 7))
1966 {
1967 r = MULTIPLY16(r, p_jpeg->quanttable[!!ci][k]);
1968 block[zag[k]] = r ;
1969 }
1970 } 1965 }
1971 else 1966 else
1972 { 1967 {
1973 if (r != 15) 1968 if (r != 15)
1974 { 1969 goto block_end;
1975 k = 64;
1976 break;
1977 }
1978 k += r;
1979 } 1970 }
1971 if ((++k) & 64)
1972 goto block_end;
1980 } /* for k */ 1973 } /* for k */
1981 } 1974 }
1982 for (; k < 64; k++) 1975 for (; k < 64; k++)
@@ -1989,6 +1982,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1989 { 1982 {
1990 k += r; 1983 k += r;
1991 check_bit_buffer(p_jpeg, s); 1984 check_bit_buffer(p_jpeg, s);
1985skip_rest:
1992 drop_bits(p_jpeg, s); 1986 drop_bits(p_jpeg, s);
1993 } 1987 }
1994 else 1988 else
@@ -1998,6 +1992,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1998 k += r; 1992 k += r;
1999 } 1993 }
2000 } /* for k */ 1994 } /* for k */
1995block_end:
2001#ifndef HAVE_LCD_COLOR 1996#ifndef HAVE_LCD_COLOR
2002 if (!ci) 1997 if (!ci)
2003#endif 1998#endif