diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-03-05 19:02:27 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-03-05 19:02:27 +0100 |
| commit | 0f8649f3c4e4307518b451ec44ecfa5eff3074c0 (patch) | |
| tree | 4e892a3ae8cfa7b7bafa12265c228a4ef0699d5f /src | |
| parent | 4c0a2ffb8159f58d1f9f0b5298770deff874895e (diff) | |
Filechooser preview of XML file shows it as a corrupt image - cont'd (#926)
Diffstat (limited to 'src')
| -rw-r--r-- | src/fl_images_core.cxx | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/fl_images_core.cxx b/src/fl_images_core.cxx index 45835fa20..de34fe3e9 100644 --- a/src/fl_images_core.cxx +++ b/src/fl_images_core.cxx @@ -126,12 +126,22 @@ 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[300]; // 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 gzip'ed *and* we can decompress the data + // 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 defined(HAVE_LIBZ) if (header[0] == 0x1f && header[1] == 0x8b) { // gzip'ed data @@ -160,8 +170,8 @@ fl_check_images(const char *name, // I - Filename // Check svg or xml signature bool found_svg = false; - if (memcmp(buf, "<svg", 4) == 0) found_svg = true; - else if (memcmp(buf, "<?xml", 5) == 0) { + 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) { |
