diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2019-03-05 22:27:12 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2019-06-12 01:43:14 +0100 |
commit | aa1a495a60ec335fcc1ee85dbe5b659d12d15d6e (patch) | |
tree | 70993951751c8a2f5765bf66d2bca1a0389a1250 | |
parent | dfc7ba4b80fccd24b4a42fe7b23ba09560b78081 (diff) | |
download | imv-aa1a495a60ec335fcc1ee85dbe5b659d12d15d6e.tar.gz |
rsvg: Determine if svg from first 4096 bytes
The previous value of 128 isn't sufficient because some hand-crafted
SVGs have comments at the start. Going for a whole page of memory seemed
like the right amount of data without becoming too slow.
-rw-r--r-- | src/backend_librsvg.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/backend_librsvg.c b/src/backend_librsvg.c index 984a351..8e1ef97 100644 --- a/src/backend_librsvg.c +++ b/src/backend_librsvg.c @@ -126,7 +126,7 @@ static int load_image(struct imv_source *src) static enum backend_result open_path(const char *path, struct imv_source **src) { /* Look for an <SVG> tag near the start of the file */ - char header[128]; + char header[4096]; FILE *f = fopen(path, "rb"); if (!f) { return BACKEND_BAD_PATH; @@ -165,9 +165,13 @@ static enum backend_result open_path(const char *path, struct imv_source **src) static enum backend_result open_memory(void *data, size_t len, struct imv_source **src) { /* Look for an <SVG> tag near the start of the file */ - char header[128]; - memcpy(header, data, sizeof header); - header[(sizeof header) - 1] = 0; + char header[4096]; + size_t header_len = sizeof header; + if (header_len > len) { + header_len = len; + } + memcpy(header, data, header_len); + header[header_len - 1] = 0; if (!strstr(header, "<SVG") && !strstr(header, "<svg")) { return BACKEND_UNSUPPORTED; } |