diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2009-02-16 12:36:50 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2009-02-16 12:36:50 +0000 |
commit | 051fdb9e7a248bf24bb845313e324421992abf61 (patch) | |
tree | 38288f0d0d8fd27c0f66dec6caaa173663796be9 | |
parent | 8ad78e1ec7b2e873953f9f476fb63b5893526c39 (diff) | |
download | busybox-w32-051fdb9e7a248bf24bb845313e324421992abf61.tar.gz busybox-w32-051fdb9e7a248bf24bb845313e324421992abf61.tar.bz2 busybox-w32-051fdb9e7a248bf24bb845313e324421992abf61.zip |
- PPMs can have comments in the header.
Thanks to Denys for pointing that out. (~+7b)
-rw-r--r-- | miscutils/fbsplash.c | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 330dd4d1d..a0f7d0dc2 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c | |||
@@ -216,36 +216,36 @@ static void fb_drawprogressbar(unsigned percent) | |||
216 | */ | 216 | */ |
217 | static void fb_drawimage(void) | 217 | static void fb_drawimage(void) |
218 | { | 218 | { |
219 | RESERVE_CONFIG_BUFFER(head, 256); | 219 | char *head, *ptr; |
220 | RESERVE_CONFIG_BUFFER(s, 80); | 220 | FILE *theme_file; |
221 | int theme_file; | ||
222 | unsigned char *pixline; | 221 | unsigned char *pixline; |
223 | unsigned i, j, width, height, line_size; | 222 | unsigned i, j, width, height, line_size; |
224 | 223 | ||
225 | memset(head, 0, sizeof(head)); | 224 | theme_file = xfopen_stdin(G.image_filename); |
226 | theme_file = open_or_warn_stdin(G.image_filename); | 225 | head = xmalloc(256); |
227 | 226 | ||
228 | // parse ppm header | 227 | // parse ppm header |
229 | while (1) { | 228 | while (1) { |
230 | if (safe_read(theme_file, s, sizeof(s)) <= 0) | 229 | if (fgets(head, 256, theme_file) == NULL |
231 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); | 230 | /* do not overrun the buffer */ |
232 | 231 | || strlen(bb_common_bufsiz1) >= sizeof(bb_common_bufsiz1) - 256) | |
233 | if (s[0] == '#') | ||
234 | continue; | ||
235 | |||
236 | if (strlen(head) + strlen(s) >= sizeof(head)) | ||
237 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); | ||
238 | |||
239 | strcat(head, s); | ||
240 | if (head[0] != 'P' || head[1] != '6') | ||
241 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); | 232 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
242 | 233 | ||
234 | ptr = memchr(head, '#', 256); | ||
235 | if (ptr != NULL) | ||
236 | *ptr = 0; /* ignore comments */ | ||
237 | strcat(bb_common_bufsiz1, head); | ||
243 | // width, height, max_color_val | 238 | // width, height, max_color_val |
244 | if (sscanf(head, "P6 %u %u %u", &width, &height, &i) == 3) | 239 | if (sscanf(bb_common_bufsiz1, "P6 %u %u %u", &width, &height, &i) == 3 |
240 | && i <= 255) | ||
245 | break; | 241 | break; |
246 | // TODO: i must be <= 255! | 242 | /* If we do not find a signature throughout the whole file then |
243 | we will diagnose this via EOF on read in the head of the loop. */ | ||
247 | } | 244 | } |
248 | 245 | ||
246 | if (ENABLE_FEATURE_CLEAN_UP) | ||
247 | free(head); | ||
248 | |||
249 | line_size = width*3; | 249 | line_size = width*3; |
250 | if (width > G.scr_var.xres) | 250 | if (width > G.scr_var.xres) |
251 | width = G.scr_var.xres; | 251 | width = G.scr_var.xres; |
@@ -257,7 +257,7 @@ static void fb_drawimage(void) | |||
257 | unsigned char *pixel = pixline; | 257 | unsigned char *pixel = pixline; |
258 | DATA *src = (DATA *)(G.addr + j * G.scr_fix.line_length); | 258 | DATA *src = (DATA *)(G.addr + j * G.scr_fix.line_length); |
259 | 259 | ||
260 | if (safe_read(theme_file, pixline, line_size) != line_size) | 260 | if (fread(pixline, 1, line_size, theme_file) != line_size) |
261 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); | 261 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
262 | for (i = 0; i < width; i++) { | 262 | for (i = 0; i < width; i++) { |
263 | unsigned thispix; | 263 | unsigned thispix; |
@@ -268,12 +268,9 @@ static void fb_drawimage(void) | |||
268 | pixel += 3; | 268 | pixel += 3; |
269 | } | 269 | } |
270 | } | 270 | } |
271 | if (ENABLE_FEATURE_CLEAN_UP) { | 271 | if (ENABLE_FEATURE_CLEAN_UP) |
272 | free(pixline); | 272 | free(pixline); |
273 | RELEASE_CONFIG_BUFFER(s); | 273 | fclose(theme_file); |
274 | RELEASE_CONFIG_BUFFER(head); | ||
275 | } | ||
276 | close(theme_file); | ||
277 | } | 274 | } |
278 | 275 | ||
279 | 276 | ||