Do sanitization before the use on 'main' mini-program (#994)
This commit is contained in:
parent
c02b40e58f
commit
c55aa147c3
20
src/main.cc
20
src/main.cc
|
@ -51,11 +51,15 @@ main (int argc, char **argv)
|
|||
|
||||
const char *font_data = nullptr;
|
||||
int len = 0;
|
||||
hb_destroy_func_t destroy;
|
||||
hb_memory_mode_t mm;
|
||||
|
||||
#ifdef HAVE_GLIB
|
||||
GMappedFile *mf = g_mapped_file_new (argv[1], false, nullptr);
|
||||
font_data = g_mapped_file_get_contents (mf);
|
||||
len = g_mapped_file_get_length (mf);
|
||||
destroy = (hb_destroy_func_t) g_mapped_file_unref;
|
||||
mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE;
|
||||
#else
|
||||
FILE *f = fopen (argv[1], "rb");
|
||||
fseek (f, 0, SEEK_END);
|
||||
|
@ -63,11 +67,23 @@ main (int argc, char **argv)
|
|||
fseek (f, 0, SEEK_SET);
|
||||
font_data = (const char *) malloc (len);
|
||||
len = fread ((char *) font_data, 1, len, f);
|
||||
destroy = free;
|
||||
mm = HB_MEMORY_MODE_WRITABLE;
|
||||
#endif
|
||||
|
||||
printf ("Opened font file %s: %d bytes long\n", argv[1], len);
|
||||
|
||||
const OpenTypeFontFile &ot = *CastP<OpenTypeFontFile> (font_data);
|
||||
Sanitizer<OpenTypeFontFile> sanitizer;
|
||||
hb_blob_t *blob = hb_blob_create (font_data, len, mm, (void *) font_data, destroy);
|
||||
hb_blob_t *font_blob = sanitizer.sanitize (blob);
|
||||
const OpenTypeFontFile* sanitized = Sanitizer<OpenTypeFontFile>::lock_instance (font_blob);
|
||||
if (sanitized == &Null (OpenTypeFontFile))
|
||||
{
|
||||
printf ("Sanitization of the file wasn't successful. Exit");
|
||||
return 1;
|
||||
}
|
||||
const OpenTypeFontFile& ot = *sanitized;
|
||||
|
||||
|
||||
switch (ot.get_tag ()) {
|
||||
case OpenTypeFontFile::TrueTypeTag:
|
||||
|
@ -197,5 +213,3 @@ main (int argc, char **argv)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue