summaryrefslogtreecommitdiffstats
path: root/src/file_jpg.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-10-28 11:13:54 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2014-10-28 11:13:54 +0100
commit3e91667fb243d0f7518f425faf92a46a2cdf573b (patch)
treead04c9330b760add50e17f1981ef0ec52cadfc83 /src/file_jpg.c
parent785805156445ff209ac22eccadccdcdde7bd740c (diff)
PhotoRec: rewrite jpg_check_dht()
Diffstat (limited to 'src/file_jpg.c')
-rw-r--r--src/file_jpg.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/file_jpg.c b/src/file_jpg.c
index 9a5c3bd..27920a2 100644
--- a/src/file_jpg.c
+++ b/src/file_jpg.c
@@ -1263,38 +1263,34 @@ static void jpg_check_picture(file_recovery_t *file_recovery)
static int jpg_check_dht(const unsigned char *buffer, const unsigned int buffer_size, const unsigned i, const unsigned int size)
{
+ unsigned int j=i+4;
/* DHT must not be shorter than 18 bytes, 1+16+1 */
/* DHT should not be longer than 1088 bytes, 4*(1+16+255) */
if(size<18)
return 2;
- if(i + 4 < buffer_size)
+ while(j < buffer_size && j < i+size)
{
- unsigned int j=i+4;
- const unsigned int tc=buffer[j] & 0x0f;
+ const unsigned int tc=buffer[j]>>4;
const unsigned int n=buffer[j] & 0x0f;
+ unsigned int l;
+ unsigned int sum=0;
/* Table class: 0 = DC table or lossless table, 1 = AC table */
if(tc > 1)
return 2;
/* Must be between 0 and 3 Huffman table */
if(n > 3)
return 2;
- {
- unsigned int l;
- unsigned int sum=0;
- if(j < buffer_size && (buffer[j]&0x0f)>3)
- return 2;
- j++;
- for(l=0; l < 16; l++)
- if(j < buffer_size)
- sum+=buffer[j+l];
- if(sum>255)
- return 2;
- j+=16;
- j+=sum;
- }
- if(j > i+size)
+ j++;
+ for(l=0; l < 16; l++)
+ if(j < buffer_size)
+ sum+=buffer[j+l];
+ if(sum>255)
return 2;
+ j+=16;
+ j+=sum;
}
+ if(j > i+size)
+ return 2;
return 0;
}