From dd2b095f8709b2fb2b7c29e0bc3969aecbb61b13 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Thu, 22 May 2014 12:11:17 +0000 Subject: Fix STR#2995: make FLTK robust to bad .xpm files git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10156 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_XPM_Image.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Fl_XPM_Image.cxx b/src/Fl_XPM_Image.cxx index 35876d635..81794b00c 100644 --- a/src/Fl_XPM_Image.cxx +++ b/src/Fl_XPM_Image.cxx @@ -60,6 +60,7 @@ Fl_XPM_Image::Fl_XPM_Image(const char *name) : Fl_Pixmap((char *const*)0) { int malloc_size = INITIALLINES; char buffer[MAXSIZE+20]; int i = 0; + int W,H,ncolors,chars_per_pixel; while (fgets(buffer,MAXSIZE+20,f)) { if (buffer[0] != '\"') continue; char *myp = buffer; @@ -107,6 +108,15 @@ Fl_XPM_Image::Fl_XPM_Image(const char *name) : Fl_Pixmap((char *const*)0) { new_data = temp_data; malloc_size += INITIALLINES; } + // first line has 4 ints: width, height, ncolors, chars_per_pixel + // followed by color segment: + // if ncolors < 0 this is FLTK (non standard) compressed colormap - all colors coded in single line of 4*ncolors bytes + // otherwise - ncolor lines of at least chars_per_pixel bytes + // followed by pic segment: H lines of at least chars_per_pixel*W bytes + // next line: would have loved to use measure_pixmap, but it doesn't return all the data! + if ((!i) && (sscanf(buffer,"%d%d%d%d", &W, &H, &ncolors, &chars_per_pixel) < 4)) goto bad_data; // first line + else if ((i > (ncolors<0?1:ncolors)) && (myp-buffer-1 0) delete[] new_data[--i]; + delete[] new_data; + if (f) fclose(f); } -- cgit v1.2.3