diff options
author | Ebrahim Byagowi <ebrahim@gnu.org> | 2018-06-17 17:04:55 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-17 17:04:55 +0430 |
commit | c53697d3f2a3fae8b68ec4c5146c7000a07e0963 (patch) | |
tree | 09c97a579dcd761ee5f00e6d02b14f24be0dcbac /util | |
parent | aa0c5df4199ef4e96df2b856c8f629e49fdd5120 (diff) |
Verbose fail when something is wrong with hb-shape/hb-view input font file (#1059)
This checks if the blob isn't empty and uses `hb_face_count`
to see if the font file passes the simple font file sanitization
so can detect if the input is actually a font and checks also
whether input font-index is out of range.
Diffstat (limited to 'util')
-rw-r--r-- | util/options.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/util/options.cc b/util/options.cc index 4c65735f..299466fe 100644 --- a/util/options.cc +++ b/util/options.cc @@ -670,6 +670,17 @@ font_options_t::get_font (void) const blob = hb_blob_create_from_file (font_file); } + if (hb_blob_get_length (blob) == 0) + fail (false, "No such file or directory, or is empty"); + + unsigned int face_count = hb_face_count (blob); + + if (face_count == 0) + fail (false, "Not a font file"); // most likely + + if (face_index > face_count) + fail (false, "The requested font index wasn't available in the file"); + /* Create the face */ hb_face_t *face = hb_face_create (blob, face_index); hb_blob_destroy (blob); |