forked from old/legacy-imlib2
XBM loader: Ignore comments and other stuff in header
Add naive signature check to avoid trivial cases where we might otherwise scan through large non-xbm file.
This commit is contained in:
parent
868f2434f1
commit
d812457afe
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* XBM loader
|
* XBM loader
|
||||||
*/
|
*/
|
||||||
|
#define _GNU_SOURCE /* memmem() */
|
||||||
#include "loader_common.h"
|
#include "loader_common.h"
|
||||||
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
@ -92,10 +93,20 @@ load2(ImlibImage * im, int load_data)
|
||||||
|
|
||||||
rc = LOAD_FAIL;
|
rc = LOAD_FAIL;
|
||||||
|
|
||||||
|
if (im->fsize < 64)
|
||||||
|
return rc; /* Not XBM */
|
||||||
|
|
||||||
fdata = mmap(NULL, im->fsize, PROT_READ, MAP_SHARED, fileno(im->fp), 0);
|
fdata = mmap(NULL, im->fsize, PROT_READ, MAP_SHARED, fileno(im->fp), 0);
|
||||||
if (fdata == MAP_FAILED)
|
if (fdata == MAP_FAILED)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
/* Signature check ("#define") allow longish initial comment */
|
||||||
|
s = fdata;
|
||||||
|
nlen = s[0] == '/' && s[1] == '*' ? 4096 : 256;
|
||||||
|
nlen = im->fsize > nlen ? nlen : im->fsize;
|
||||||
|
if (!memmem(s, nlen, "#define", 7))
|
||||||
|
goto quit;
|
||||||
|
|
||||||
mm_init(fdata, im->fsize);
|
mm_init(fdata, im->fsize);
|
||||||
|
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
|
@ -134,7 +145,7 @@ load2(ImlibImage * im, int load_data)
|
||||||
im->h = val;
|
im->h = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(tok1, "static") == 0)
|
else if (strcmp(tok1, "static") == 0 && strstr(buf + 6, "_bits"))
|
||||||
{
|
{
|
||||||
if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
|
if (!IMAGE_DIMENSIONS_OK(im->w, im->h))
|
||||||
goto quit;
|
goto quit;
|
||||||
|
@ -155,7 +166,7 @@ load2(ImlibImage * im, int load_data)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
goto quit;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue