1 |
dragonheart 09/04/23 14:12:39 |
2 |
|
3 |
Added: testdisk-6.11-exif_bound_checking.patch |
4 |
Log: |
5 |
version bump |
6 |
(Portage version: 2.2_rc31/cvs/Linux x86_64) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 app-admin/testdisk/files/testdisk-6.11-exif_bound_checking.patch |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/testdisk/files/testdisk-6.11-exif_bound_checking.patch?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/testdisk/files/testdisk-6.11-exif_bound_checking.patch?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: testdisk-6.11-exif_bound_checking.patch |
15 |
=================================================================== |
16 |
diff -ru testdisk-6.11/src/file_jpg.c testdisk-6.11.1/src/file_jpg.c |
17 |
--- testdisk-6.11/src/file_jpg.c 2009-04-08 12:24:02.000000000 +0200 |
18 |
+++ testdisk-6.11.1/src/file_jpg.c 2009-04-23 12:19:27.000000000 +0200 |
19 |
@@ -100,14 +100,10 @@ |
20 |
if(buffer[i]!=0xff) |
21 |
return 0; |
22 |
/* 0xe0 APP0 */ |
23 |
+ /* 0xef APP15 */ |
24 |
/* 0xfe COM */ |
25 |
/* 0xdb DQT */ |
26 |
- if(buffer[i+1]==0xe0 || |
27 |
- buffer[i+1]==0xfe || |
28 |
- buffer[i+1]==0xdb) |
29 |
- { |
30 |
- } |
31 |
- else if(buffer[i+1]==0xe1) |
32 |
+ if(buffer[i+1]==0xe1) |
33 |
{ /* APP1 Exif information */ |
34 |
if(i+0x0A < buffer_size && 2+(buffer[i+2]<<8)+buffer[i+3] > 0x0A) |
35 |
{ |
36 |
@@ -117,12 +113,17 @@ |
37 |
file_recovery_new->time=get_date_from_tiff_header((const TIFFHeader*)&buffer[i+0x0A], tiff_size); |
38 |
} |
39 |
} |
40 |
+ else if((buffer[i+1]>=0xe0 && buffer[i+1]<=0xef) || |
41 |
+ buffer[i+1]==0xfe || |
42 |
+ buffer[i+1]==0xdb) |
43 |
+ { |
44 |
+ } |
45 |
else |
46 |
{ |
47 |
reset_file_recovery(file_recovery_new); |
48 |
file_recovery_new->extension=file_hint_jpg.extension; |
49 |
file_recovery_new->file_check=&file_check_jpg; |
50 |
- file_recovery_new->min_filesize=288; |
51 |
+ file_recovery_new->min_filesize=(i>288?i:288); |
52 |
file_recovery_new->data_check=&data_check_jpg; |
53 |
file_recovery_new->calculated_file_size=2; |
54 |
return 1; |
55 |
@@ -511,7 +512,7 @@ |
56 |
const unsigned int thumb_offset=thumb_data-(const char*)buffer; |
57 |
const unsigned int thumb_size=ifbytecount-(const char*)tiff; |
58 |
unsigned int j_old; |
59 |
- if(thumb_offset+thumb_size < sizeof(buffer)) |
60 |
+ if(thumb_offset < sizeof(buffer) && thumb_offset+thumb_size < sizeof(buffer)) |
61 |
{ |
62 |
unsigned int j=thumb_offset+2; |
63 |
unsigned int thumb_sos_found=0; |
64 |
diff -ru testdisk-6.11/src/file_tiff.c testdisk-6.11.1/src/file_tiff.c |
65 |
--- testdisk-6.11/src/file_tiff.c 2009-04-13 12:00:24.000000000 +0200 |
66 |
+++ testdisk-6.11.1/src/file_tiff.c 2009-04-23 12:12:21.000000000 +0200 |
67 |
@@ -65,6 +65,10 @@ |
68 |
const uint32_t *tiff_next_diroff; |
69 |
const TIFFDirEntry *ifd; |
70 |
unsigned int j; |
71 |
+ /* Bound checking */ |
72 |
+ if((const char*)ifd0 < (const char*)tiff || |
73 |
+ (const char*)(ifd0+1) > (const char*)tiff + tiff_size) |
74 |
+ return NULL; |
75 |
for(j=0, ifd=&ifd0->ifd; |
76 |
(const char*)(ifd+1) <= (const char*)tiff+tiff_size && j<be16(ifd0->nbr_fields); |
77 |
j++, ifd++) |
78 |
@@ -75,7 +79,9 @@ |
79 |
exififd=(const struct ifd_header *)((const char*)tiff + be32(ifd->tdir_offset)); |
80 |
} |
81 |
tiff_next_diroff=(const uint32_t *)ifd; |
82 |
- if(exififd!=NULL) |
83 |
+ if(exififd!=NULL && |
84 |
+ (const char*)exififd > (const char*)tiff && |
85 |
+ (const char*)(exififd+1) <= (const char*)tiff + tiff_size) |
86 |
{ /* Exif */ |
87 |
for(j=0, ifd=&exififd->ifd; |
88 |
(const char*)(ifd+1) <= (const char*)tiff+tiff_size && j<be16(exififd->nbr_fields); |
89 |
@@ -89,6 +95,9 @@ |
90 |
if(be32(*tiff_next_diroff)>0) |
91 |
{ |
92 |
const const struct ifd_header *ifd1=(const struct ifd_header*)((const char *)tiff+be32(*tiff_next_diroff)); |
93 |
+ if((const char*)ifd1 <= (const char*)tiff || |
94 |
+ (const char*)(ifd1+1) > (const char*)tiff+tiff_size) |
95 |
+ return NULL; |
96 |
for(j=0, ifd=&ifd1->ifd; |
97 |
(const char*)(ifd+1) <= (const char*)tiff+tiff_size && j<be16(ifd1->nbr_fields); |
98 |
j++, ifd++) |
99 |
@@ -107,6 +116,10 @@ |
100 |
const uint32_t *tiff_next_diroff; |
101 |
const TIFFDirEntry *ifd; |
102 |
unsigned int j; |
103 |
+ /* Bound checking */ |
104 |
+ if((const char*)ifd0 < (const char*)tiff || |
105 |
+ (const char*)(ifd0+1) > (const char*)tiff + tiff_size) |
106 |
+ return NULL; |
107 |
for(j=0, ifd=&ifd0->ifd; |
108 |
(const char*)(ifd+1) <= (const char*)tiff+tiff_size && j<le16(ifd0->nbr_fields); |
109 |
j++, ifd++) |
110 |
@@ -117,7 +130,9 @@ |
111 |
exififd=(const struct ifd_header *)((const char*)tiff + le32(ifd->tdir_offset)); |
112 |
} |
113 |
tiff_next_diroff=(const uint32_t *)ifd; |
114 |
- if(exififd!=NULL) |
115 |
+ if(exififd!=NULL && |
116 |
+ (const char*)exififd > (const char*)tiff && |
117 |
+ (const char*)(exififd+1) <= (const char*)tiff + tiff_size) |
118 |
{ /* Exif */ |
119 |
for(j=0, ifd=&exififd->ifd; |
120 |
(const char*)(ifd+1) <= (const char*)tiff+tiff_size && j<le16(exififd->nbr_fields); |
121 |
@@ -131,6 +146,10 @@ |
122 |
if(le32(*tiff_next_diroff)>0) |
123 |
{ |
124 |
const const struct ifd_header *ifd1=(const struct ifd_header*)((const char *)tiff+le32(*tiff_next_diroff)); |
125 |
+ /* Bound checking */ |
126 |
+ if((const char*)(ifd1) <= (const char*)tiff || |
127 |
+ (const char*)(ifd1+1) > (const char*)tiff+tiff_size) |
128 |
+ return NULL; |
129 |
for(j=0, ifd=&ifd1->ifd; |
130 |
(const char*)(ifd+1) <= (const char*)tiff+tiff_size && j<le16(ifd1->nbr_fields); |
131 |
j++, ifd++) |
132 |
@@ -168,11 +187,11 @@ |
133 |
/* DateTimeOriginal */ |
134 |
date_asc=find_tag_from_tiff_header(tiff, tiff_size, 0x9003); |
135 |
/* DateTimeDigitalized*/ |
136 |
- if(date_asc==NULL || &date_asc[18] >= (const char *)tiff + tiff_size) |
137 |
+ if(date_asc==NULL || date_asc < (const char *)tiff || &date_asc[18] >= (const char *)tiff + tiff_size) |
138 |
date_asc=find_tag_from_tiff_header(tiff, tiff_size, 0x9004); |
139 |
- if(date_asc==NULL || &date_asc[18] >= (const char *)tiff + tiff_size) |
140 |
+ if(date_asc==NULL || date_asc < (const char *)tiff || &date_asc[18] >= (const char *)tiff + tiff_size) |
141 |
date_asc=find_tag_from_tiff_header(tiff, tiff_size, 0x132); |
142 |
- if(date_asc==NULL || &date_asc[18] >= (const char *)tiff + tiff_size) |
143 |
+ if(date_asc==NULL || date_asc < (const char *)tiff || &date_asc[18] >= (const char *)tiff + tiff_size) |
144 |
return (time_t)0; |
145 |
memset(&tm_time, 0, sizeof(tm_time)); |
146 |
tm_time.tm_sec=(date_asc[17]-'0')*10+(date_asc[18]-'0'); /* seconds 0-59 */ |