diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-03-11 11:36:47 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-03-11 11:36:47 +0100 |
| commit | 20e8da9dfd9bd10a6531369b1f675a2f7de0a2e5 (patch) | |
| tree | dff9262f3df2ccca37100f98749252384d070910 /src | |
| parent | 7bbe75c84ee9afae7315ac888d4207cf74903eef (diff) | |
Fix: Filechooser preview of XML file shows it as a corrupt image (#926)
Diffstat (limited to 'src')
| -rw-r--r-- | src/fl_images_core.cxx | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/src/fl_images_core.cxx b/src/fl_images_core.cxx index de34fe3e9..d9f8d41a5 100644 --- a/src/fl_images_core.cxx +++ b/src/fl_images_core.cxx @@ -36,7 +36,6 @@ #include <FL/fl_utf8.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> #include "flstring.h" #if defined(HAVE_LIBZ) #include <zlib.h> @@ -126,22 +125,12 @@ fl_check_images(const char *name, // I - Filename // SVG or SVGZ (gzip'ed SVG) #ifdef FLTK_USE_SVG - uchar header2[300]; // buffer for decompression + uchar header2[64]; // buffer for decompression uchar *buf = header; // original header data int count = headerlen; // original header data size // Note: variables 'buf' and 'count' may be overwritten subsequently - // if the image data is xml or gzip'ed *and* we can decompress the data - - if (count >= 5 && memcmp(header, "<?xml", 5) == 0) { - FILE *in = fl_fopen(name, "r"); - if (in) { - buf = header2; - count = sizeof(header2); - count = fread(header2, 1, count, in); - fclose(in); - } - } + // if the image data is gzip'ed *and* we can decompress the data # if defined(HAVE_LIBZ) if (header[0] == 0x1f && header[1] == 0x8b) { // gzip'ed data @@ -169,18 +158,17 @@ fl_check_images(const char *name, // I - Filename } // Check svg or xml signature - bool found_svg = false; - if (count >= 4 && memcmp(buf, "<svg", 4) == 0) found_svg = true; - else if (count >= 5 && memcmp(buf, "<?xml", 5) == 0) { - uchar *p = buf; - do { - if (memcmp(p, "<svg", 4) == 0) { - found_svg = true; - break; - } - } while (++p < buf + count - 4); + + while (count && isspace(buf[0])) { buf++; count--; } + if ((count >= 5 && + (memcmp(buf, "<?xml", 5) == 0 || + memcmp(buf, "<svg", 4) == 0 || + memcmp(buf, "<!--", 4) == 0))) { + Fl_SVG_Image *image = new Fl_SVG_Image(name); + if (image->w() && image->h()) + return image; + delete image; } - if (found_svg) return new Fl_SVG_Image(name); #endif // FLTK_USE_SVG // unknown image format |
