mirror of
https://github.com/fltk/fltk.git
synced 2026-05-29 04:26:27 +08:00
Check for valid length and simplify BOM check (#247)
This commit is contained in:
+17
-2
@@ -145,8 +145,23 @@ fl_check_images(const char *name, // I - Filename
|
|||||||
buf += lutf8; count -= lutf8;
|
buf += lutf8; count -= lutf8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((count >= 5 && memcmp(buf, "<?xml", 5) == 0) ||
|
// Check if we have a UTF-8 BOM in the first three bytes (issue #247).
|
||||||
(count >= 4 && memcmp(buf, "<svg", 4) == 0))
|
// If yes we need at least 5 more bytes to recognize the signature.
|
||||||
|
// Note: BOM (Byte Order Marker) in UTF-8 is not recommended but allowed.
|
||||||
|
|
||||||
|
if (count >= 8) {
|
||||||
|
const uchar bom[3] = { 0xef, 0xbb, 0xbf };
|
||||||
|
if (memcmp(buf, bom, 3) == 0) {
|
||||||
|
buf += 3;
|
||||||
|
count -= 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check svg or xml signature
|
||||||
|
|
||||||
|
if ((count >= 5 &&
|
||||||
|
(memcmp(buf, "<?xml", 5) == 0 ||
|
||||||
|
memcmp(buf, "<svg ", 5) == 0)))
|
||||||
return new Fl_SVG_Image(name);
|
return new Fl_SVG_Image(name);
|
||||||
#endif // FLTK_USE_SVG
|
#endif // FLTK_USE_SVG
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user