1 |
caleb 08/12/28 23:05:59 |
2 |
|
3 |
Added: qt-faststart-0.2.diff |
4 |
Log: |
5 |
Version bump, with patch from 249953 |
6 |
(Portage version: 2.2_rc18/cvs/Linux 2.6.18-xenU-ec2-v1.0 i686) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 media-video/qt-faststart/files/qt-faststart-0.2.diff |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/media-video/qt-faststart/files/qt-faststart-0.2.diff?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/media-video/qt-faststart/files/qt-faststart-0.2.diff?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: qt-faststart-0.2.diff |
15 |
=================================================================== |
16 |
--- qt-faststart.c 2008-12-05 11:33:16 -0500 |
17 |
+++ qt-faststart.c 2008-12-05 11:45:19 -0500 |
18 |
@@ -1,9 +1,16 @@ |
19 |
/* |
20 |
- * qt-faststart.c, v0.1 |
21 |
+ * qt-faststart.c, v0.2 |
22 |
+ * |
23 |
* by Mike Melanson (melanson@××××××.net) |
24 |
* This file is placed in the public domain. Use the program however you |
25 |
* see fit. |
26 |
* |
27 |
+ * ChangLog |
28 |
+ * 20081205 - Andrew Andkjar <andkjar@××××××.net> |
29 |
+ * qt-faststart.c v0.2 - fixes for infinite loops caused by various malformed input files |
30 |
+ * Pre 20081205 - Mike Melanson <melanson@××××××.net> |
31 |
+ * qt-faststart.c v0.1 - original version |
32 |
+ * |
33 |
* This utility rearranges a Quicktime file such that the moov atom |
34 |
* is in front of the data, thus facilitating network streaming. |
35 |
* |
36 |
@@ -70,32 +77,32 @@ |
37 |
|
38 |
int main(int argc, char *argv[]) |
39 |
{ |
40 |
- FILE *infile; |
41 |
- FILE *outfile; |
42 |
+ FILE *infile = NULL; |
43 |
+ FILE *outfile = NULL; |
44 |
unsigned char atom_bytes[ATOM_PREAMBLE_SIZE]; |
45 |
uint32_t atom_type = 0; |
46 |
uint64_t atom_size = 0; |
47 |
- uint64_t last_offset; |
48 |
- unsigned char *moov_atom; |
49 |
- unsigned char *ftyp_atom = 0; |
50 |
- uint64_t moov_atom_size; |
51 |
+ uint64_t last_offset = 0; |
52 |
+ unsigned char *moov_atom = NULL; |
53 |
+ unsigned char *ftyp_atom = NULL; |
54 |
+ uint64_t moov_atom_size = 0; |
55 |
uint64_t ftyp_atom_size = 0; |
56 |
- uint64_t i, j; |
57 |
- uint32_t offset_count; |
58 |
- uint64_t current_offset; |
59 |
+ uint64_t i = 0, j = 0; |
60 |
+ uint32_t offset_count = 0; |
61 |
+ uint64_t current_offset = 0; |
62 |
uint64_t start_offset = 0; |
63 |
unsigned char copy_buffer[COPY_BUFFER_SIZE]; |
64 |
- int bytes_to_copy; |
65 |
+ int bytes_to_copy = 0; |
66 |
|
67 |
if (argc != 3) { |
68 |
- printf ("Usage: qt-faststart <infile.mov> <outfile.mov>\n"); |
69 |
+ fprintf(stderr, "Usage: qt-faststart <infile.mov> <outfile.mov>\n"); |
70 |
return 0; |
71 |
} |
72 |
|
73 |
infile = fopen(argv[1], "rb"); |
74 |
if (!infile) { |
75 |
perror(argv[1]); |
76 |
- return 1; |
77 |
+ goto error_out; |
78 |
} |
79 |
|
80 |
/* traverse through the atoms in the file to make sure that 'moov' is |
81 |
@@ -107,6 +114,11 @@ |
82 |
atom_size = (uint32_t)BE_32(&atom_bytes[0]); |
83 |
atom_type = BE_32(&atom_bytes[4]); |
84 |
|
85 |
+ if(atom_size < ATOM_PREAMBLE_SIZE) { |
86 |
+ fprintf(stderr, "fatal error: bad atom size\n"); |
87 |
+ goto error_out; |
88 |
+ } |
89 |
+ |
90 |
if ((atom_type != FREE_ATOM) && |
91 |
(atom_type != JUNK_ATOM) && |
92 |
(atom_type != MDAT_ATOM) && |
93 |
@@ -116,7 +128,7 @@ |
94 |
(atom_type != WIDE_ATOM) && |
95 |
(atom_type != PICT_ATOM) && |
96 |
(atom_type != FTYP_ATOM)) { |
97 |
- printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n"); |
98 |
+ fprintf(stderr, "encountered non-QT top-level atom (is this a Quicktime file?)\n"); |
99 |
break; |
100 |
} |
101 |
|
102 |
@@ -125,70 +137,82 @@ |
103 |
ftyp_atom_size = atom_size; |
104 |
ftyp_atom = malloc(ftyp_atom_size); |
105 |
if (!ftyp_atom) { |
106 |
- printf ("could not allocate 0x%llX byte for ftyp atom\n", |
107 |
- atom_size); |
108 |
- fclose(infile); |
109 |
- return 1; |
110 |
+ fprintf(stderr, "could not allocate 0x%llX byte for ftyp atom\n", atom_size); |
111 |
+ goto error_out; |
112 |
} |
113 |
- fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR); |
114 |
+ |
115 |
+ if(0 != fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR)) { |
116 |
+ perror(argv[1]); |
117 |
+ goto error_out; |
118 |
+ } |
119 |
+ |
120 |
if (fread(ftyp_atom, atom_size, 1, infile) != 1) { |
121 |
perror(argv[1]); |
122 |
- free(ftyp_atom); |
123 |
- fclose(infile); |
124 |
- return 1; |
125 |
+ goto error_out; |
126 |
} |
127 |
start_offset = ftello(infile); |
128 |
+ if(start_offset < 0) { |
129 |
+ perror(argv[1]); |
130 |
+ goto error_out; |
131 |
+ } |
132 |
continue; |
133 |
} |
134 |
|
135 |
/* 64-bit special case */ |
136 |
if (atom_size == 1) { |
137 |
if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { |
138 |
- break; |
139 |
+ break; |
140 |
} |
141 |
atom_size = BE_64(&atom_bytes[0]); |
142 |
- fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR); |
143 |
+ if(0 != fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR)) { |
144 |
+ perror(argv[1]); |
145 |
+ goto error_out; |
146 |
+ } |
147 |
} else { |
148 |
- fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR); |
149 |
+ if(0 != fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR)) { |
150 |
+ perror(argv[1]); |
151 |
+ goto error_out; |
152 |
+ } |
153 |
} |
154 |
} |
155 |
|
156 |
if (atom_type != MOOV_ATOM) { |
157 |
- printf ("last atom in file was not a moov atom\n"); |
158 |
- fclose(infile); |
159 |
- return 0; |
160 |
+ fprintf(stderr, "last atom in file was not a moov atom\n"); |
161 |
+ goto error_out; |
162 |
} |
163 |
|
164 |
/* moov atom was, in fact, the last atom in the chunk; load the whole |
165 |
* moov atom */ |
166 |
- fseeko(infile, -atom_size, SEEK_END); |
167 |
+ if(0 != fseeko(infile, -atom_size, SEEK_END)) { |
168 |
+ perror(argv[1]); |
169 |
+ goto error_out; |
170 |
+ } |
171 |
last_offset = ftello(infile); |
172 |
+ if(last_offset < 0) { |
173 |
+ perror(argv[1]); |
174 |
+ goto error_out; |
175 |
+ } |
176 |
moov_atom_size = atom_size; |
177 |
moov_atom = malloc(moov_atom_size); |
178 |
if (!moov_atom) { |
179 |
- printf ("could not allocate 0x%llX byte for moov atom\n", |
180 |
- atom_size); |
181 |
- fclose(infile); |
182 |
- return 1; |
183 |
+ fprintf(stderr, "could not allocate 0x%llX byte for moov atom\n", atom_size); |
184 |
+ goto error_out; |
185 |
} |
186 |
if (fread(moov_atom, atom_size, 1, infile) != 1) { |
187 |
perror(argv[1]); |
188 |
- free(moov_atom); |
189 |
- fclose(infile); |
190 |
- return 1; |
191 |
+ goto error_out; |
192 |
} |
193 |
|
194 |
/* this utility does not support compressed atoms yet, so disqualify |
195 |
* files with compressed QT atoms */ |
196 |
if (BE_32(&moov_atom[12]) == CMOV_ATOM) { |
197 |
- printf ("this utility does not support compressed moov atoms yet\n"); |
198 |
- free(moov_atom); |
199 |
- fclose(infile); |
200 |
- return 1; |
201 |
+ fprintf(stderr, "this utility does not support compressed moov atoms yet\n"); |
202 |
+ goto error_out; |
203 |
} |
204 |
|
205 |
/* close; will be re-opened later */ |
206 |
fclose(infile); |
207 |
+ infile = NULL; |
208 |
|
209 |
/* crawl through the moov chunk in search of stco or co64 atoms */ |
210 |
for (i = 4; i < moov_atom_size - 4; i++) { |
211 |
@@ -198,8 +222,7 @@ |
212 |
atom_size = BE_32(&moov_atom[i - 4]); |
213 |
if (i + atom_size - 4 > moov_atom_size) { |
214 |
printf (" bad atom size\n"); |
215 |
- free(moov_atom); |
216 |
- return 1; |
217 |
+ goto error_out; |
218 |
} |
219 |
offset_count = BE_32(&moov_atom[i + 8]); |
220 |
for (j = 0; j < offset_count; j++) { |
221 |
@@ -216,8 +239,7 @@ |
222 |
atom_size = BE_32(&moov_atom[i - 4]); |
223 |
if (i + atom_size - 4 > moov_atom_size) { |
224 |
printf (" bad atom size\n"); |
225 |
- free(moov_atom); |
226 |
- return 1; |
227 |
+ goto error_out; |
228 |
} |
229 |
offset_count = BE_32(&moov_atom[i + 8]); |
230 |
for (j = 0; j < offset_count; j++) { |
231 |
@@ -240,21 +262,21 @@ |
232 |
infile = fopen(argv[1], "rb"); |
233 |
if (!infile) { |
234 |
perror(argv[1]); |
235 |
- free(moov_atom); |
236 |
- return 1; |
237 |
+ goto error_out; |
238 |
} |
239 |
|
240 |
if (start_offset > 0) { /* seek after ftyp atom */ |
241 |
- fseeko(infile, start_offset, SEEK_SET); |
242 |
+ if(0 != fseeko(infile, start_offset, SEEK_SET)) { |
243 |
+ perror(argv[1]); |
244 |
+ goto error_out; |
245 |
+ } |
246 |
last_offset -= start_offset; |
247 |
} |
248 |
|
249 |
outfile = fopen(argv[2], "wb"); |
250 |
if (!outfile) { |
251 |
perror(argv[2]); |
252 |
- fclose(outfile); |
253 |
- free(moov_atom); |
254 |
- return 1; |
255 |
+ goto error_out; |
256 |
} |
257 |
|
258 |
/* dump the same ftyp atom */ |
259 |
@@ -295,17 +317,16 @@ |
260 |
|
261 |
fclose(infile); |
262 |
fclose(outfile); |
263 |
- free(moov_atom); |
264 |
- if (ftyp_atom_size > 0) |
265 |
- free(ftyp_atom); |
266 |
- |
267 |
+ free(moov_atom); |
268 |
+ free(ftyp_atom); |
269 |
return 0; |
270 |
|
271 |
error_out: |
272 |
- fclose(infile); |
273 |
- fclose(outfile); |
274 |
+ if(infile) |
275 |
+ fclose(infile); |
276 |
+ if(outfile) |
277 |
+ fclose(outfile); |
278 |
free(moov_atom); |
279 |
- if (ftyp_atom_size > 0) |
280 |
- free(ftyp_atom); |
281 |
+ free(ftyp_atom); |
282 |
return 1; |
283 |
} |