summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHin-Tak Leung <hintak@ghostscript.com>2013-06-25 09:05:10 +0100
committerChris Liddell <chris.liddell@artifex.com>2013-06-25 09:06:51 +0100
commit341dfa13b8ad4afadf8b2a8a7302422755911b36 (patch)
tree89ae66ba81b2ac7d107cbe6f485c7aad71fad169
parent200dc18647ae24995e28607f838d77affbfc7638 (diff)
downloadghostpdl-341dfa13b8ad4afadf8b2a8a7302422755911b36.tar.gz
Bug 690692: more robust check for TTF/OTF files
No cluster differences.
-rw-r--r--gs/Resource/Init/gs_ttf.ps21
1 files changed, 13 insertions, 8 deletions
diff --git a/gs/Resource/Init/gs_ttf.ps b/gs/Resource/Init/gs_ttf.ps
index 0dbc20614..7893764bd 100644
--- a/gs/Resource/Init/gs_ttf.ps
+++ b/gs/Resource/Init/gs_ttf.ps
@@ -41,21 +41,17 @@
% Closes the file in either case.
/.findnonttfontvalue /.findfontvalue load def
/.findfontvalue {
- 1 index read {
- 2 index 1 index unread
- % beginning with binary 0 or 't' (TrueType), or 'O' (OpenType)
- dup 0 eq 1 index (O) 0 get eq or exch (t) 0 get eq or {
+ 1 index .is_ttf_or_otf {
% If this is a font at all, it's a TrueType font.
dup /FontType eq {
pop closefile 42 //true
} {
dup /FontName eq { pop .findttfontname } { pop closefile //false } ifelse
} ifelse
- } {
+ } {
% Not a TrueType font.
.findnonttfontvalue
- } ifelse
- } { pop closefile //false } ifelse
+ } ifelse
} bind def
% <file> .findttfontname <fname> true
@@ -65,7 +61,9 @@
//true 0 .loadttfonttables
tabdict /name .knownget {
dup 8 getu32 f exch setfileposition
- 12 getu32 string f exch readstring pop
+ 12 getu32
+ dup 65535 gt { pop 65535 } if % protect against extremely large name
+ string f exch readstring pop
dup
6 findname not {
4 findname % Try FullName
@@ -82,6 +80,7 @@
% Load a font file that might be a TrueType font.
/tt_tag_dict << <00010000> 0 (true) 0 (typ1) 0 (ttcf) 0 >> readonly def
+/ttf_otf_tag_dict << <00010000> 0 (true) 0 (typ1) 0 (ttcf) 0 (OTTO) 0>> readonly def
% <file> .loadfontfile -
/.loadnonttfontfile /.loadfontfile load def
@@ -95,7 +94,13 @@
} ifelse
} bind def
+% <file> .is_ttf_or_otf <bool>
+/.is_ttf_or_otf {
+ dup 0 setfileposition (1234) .peekstring { //ttf_otf_tag_dict exch known } { //false } ifelse
+} bind def
+
currentdict /tt_tag_dict .undef
+currentdict /ttf_otf_tag_dict .undef
% ---------------- Automatic Type 42 generation ---------------- %