Bug 736435 - Restore GetProcAddress check for t2embed library. r=jdaggett
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Mon, 19 Mar 2012 18:52:08 -0400
changeset 89764 d4fa7d697295c14fa625d7568316ddbe4e891945
parent 89763 879bb8e92148d66805261e4c3d7c168243004a01
child 89765 b3e48b6d942bcded59024847320f223443fbb7f5
push id7311
push userryanvm@gmail.com
push dateMon, 19 Mar 2012 22:52:14 +0000
treeherdermozilla-inbound@b3e48b6d942b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs736435
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 736435 - Restore GetProcAddress check for t2embed library. r=jdaggett
gfx/thebes/gfxGDIFontList.cpp
toolkit/library/Makefile.in
--- a/gfx/thebes/gfxGDIFontList.cpp
+++ b/gfx/thebes/gfxGDIFontList.cpp
@@ -102,30 +102,46 @@ BuildKeyNameFromFontName(nsAString &aNam
     if (aName.Length() >= LF_FACESIZE)
         aName.Truncate(LF_FACESIZE - 1);
     ToLowerCase(aName);
 }
 
 // Implementation of gfxPlatformFontList for Win32 GDI,
 // using GDI font enumeration APIs to get the list of fonts
 
-static HMODULE fontlib;
+typedef LONG
+(WINAPI *TTLoadEmbeddedFontProc)(HANDLE* phFontReference, ULONG ulFlags,
+                                 ULONG* pulPrivStatus, ULONG ulPrivs,
+                                 ULONG* pulStatus,
+                                 READEMBEDPROC lpfnReadFromStream,
+                                 LPVOID lpvReadStream,
+                                 LPWSTR szWinFamilyName, 
+                                 LPSTR szMacFamilyName,
+                                 TTLOADINFO* pTTLoadInfo);
+
+typedef LONG
+(WINAPI *TTDeleteEmbeddedFontProc)(HANDLE hFontReference, ULONG ulFlags,
+                                   ULONG* pulStatus);
+
+
+static TTLoadEmbeddedFontProc TTLoadEmbeddedFontPtr = nsnull;
+static TTDeleteEmbeddedFontProc TTDeleteEmbeddedFontPtr = nsnull;
 
 class WinUserFontData : public gfxUserFontData {
 public:
     WinUserFontData(HANDLE aFontRef, bool aIsEmbedded)
         : mFontRef(aFontRef), mIsEmbedded(aIsEmbedded)
     { }
 
     virtual ~WinUserFontData()
     {
         if (mIsEmbedded) {
             ULONG pulStatus;
             LONG err;
-            err = TTDeleteEmbeddedFont(mFontRef, 0, &pulStatus);
+            err = TTDeleteEmbeddedFontPtr(mFontRef, 0, &pulStatus);
 #if DEBUG
             if (err != E_NONE) {
                 char buf[256];
                 sprintf(buf, "error deleting embedded font handle (%p) - TTDeleteEmbeddedFont returned %8.8x", mFontRef, err);
                 NS_ASSERTION(err == E_NONE, buf);
             }
 #endif
         } else {
@@ -571,21 +587,17 @@ GDIFontFamily::FindStyleVariations()
  * gfxGDIFontList
  *
  */
 
 gfxGDIFontList::gfxGDIFontList()
 {
     mFontSubstitutes.Init(50);
 
-    // Make sure the t2embed library is available because it may be
-    // disabled to work around security vulnerabilities.
-    if (!fontlib) {
-        fontlib = LoadLibraryW(L"t2embed.dll");
-    }
+    InitializeFontEmbeddingProcs();
 }
 
 static void
 RemoveCharsetFromFontSubstitute(nsAString &aName)
 {
     PRInt32 comma = aName.FindChar(PRUnichar(','));
     if (comma >= 0)
         aName.Truncate(comma);
@@ -762,16 +774,27 @@ gfxGDIFontList::LookupLocalFont(const gf
     if (!fe)
         return nsnull;
 
     fe->mIsUserFont = true;
     fe->mIsLocalUserFont = true;
     return fe;
 }
 
+void gfxGDIFontList::InitializeFontEmbeddingProcs()
+{
+    static HMODULE fontlib = LoadLibraryW(L"t2embed.dll");
+    if (!fontlib)
+        return;
+    TTLoadEmbeddedFontPtr = (TTLoadEmbeddedFontProc)
+        GetProcAddress(fontlib, "TTLoadEmbeddedFont");
+    TTDeleteEmbeddedFontPtr = (TTDeleteEmbeddedFontProc)
+        GetProcAddress(fontlib, "TTDeleteEmbeddedFont");
+}
+
 // used to control stream read by Windows TTLoadEmbeddedFont API
 
 class EOTFontStreamReader {
 public:
     EOTFontStreamReader(const PRUint8 *aFontData, PRUint32 aLength, PRUint8 *aEOTHeader, 
                            PRUint32 aEOTHeaderLen, FontDataOverlay *aNameOverlay)
         : mCurrentChunk(0), mChunkOffset(0)
     {
@@ -865,34 +888,30 @@ gfxGDIFontList::MakePlatformFont(const g
     struct FontDataDeleter {
         FontDataDeleter(const PRUint8 *aFontData)
             : mFontData(aFontData) { }
         ~FontDataDeleter() { NS_Free((void*)mFontData); }
         const PRUint8 *mFontData;
     };
     FontDataDeleter autoDelete(aFontData);
 
-    // if the t2embed library isn't available, bail
-    if (!fontlib)
-        return nsnull;
-
     bool hasVertical;
     bool isCFF = gfxFontUtils::IsCffFont(aFontData, hasVertical);
 
     nsresult rv;
     HANDLE fontRef = nsnull;
     bool isEmbedded = false;
 
     nsAutoString uniqueName;
     rv = gfxFontUtils::MakeUniqueUserFontName(uniqueName);
     if (NS_FAILED(rv))
         return nsnull;
 
-    // for TTF fonts, first try using the t2embed library
-    if (!isCFF) {
+    // for TTF fonts, first try using the t2embed library if available
+    if (!isCFF && TTLoadEmbeddedFontPtr && TTDeleteEmbeddedFontPtr) {
         // TrueType-style glyphs, use EOT library
         AutoFallibleTArray<PRUint8,2048> eotHeader;
         PRUint8 *buffer;
         PRUint32 eotlen;
 
         isEmbedded = true;
         PRUint32 nameLen = NS_MIN<PRUint32>(uniqueName.Length(), LF_FACESIZE - 1);
         nsAutoString fontName(Substring(uniqueName, 0, nameLen));
@@ -907,21 +926,21 @@ gfxGDIFontList::MakePlatformFont(const g
             eotlen = eotHeader.Length();
             buffer = reinterpret_cast<PRUint8*> (eotHeader.Elements());
             
             PRInt32 ret;
             ULONG privStatus, pulStatus;
             EOTFontStreamReader eotReader(aFontData, aLength, buffer, eotlen,
                                           &overlayNameData);
 
-            ret = TTLoadEmbeddedFont(&fontRef, TTLOAD_PRIVATE, &privStatus,
-                                     LICENSE_PREVIEWPRINT, &pulStatus,
-                                     EOTFontStreamReader::ReadEOTStream,
-                                     &eotReader,
-                                     (PRUnichar*)(fontName.get()), 0, 0);
+            ret = TTLoadEmbeddedFontPtr(&fontRef, TTLOAD_PRIVATE, &privStatus,
+                                        LICENSE_PREVIEWPRINT, &pulStatus,
+                                        EOTFontStreamReader::ReadEOTStream,
+                                        &eotReader,
+                                        (PRUnichar*)(fontName.get()), 0, 0);
             if (ret != E_NONE) {
                 fontRef = nsnull;
                 char buf[256];
                 sprintf(buf, "font (%s) not loaded using TTLoadEmbeddedFont - error %8.8x", NS_ConvertUTF16toUTF8(aProxyEntry->FamilyName()).get(), ret);
                 NS_WARNING(buf);
             }
         }
     }
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -516,34 +516,33 @@ ifeq ($(OS_ARCH),SunOS)
 ifdef GNU_CC
 EXTRA_DSO_LDOPTS += -lelf
 else
 EXTRA_DSO_LDOPTS += -lelf -ldemangle
 endif
 endif
 
 ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,shell32 ole32 version winspool comdlg32 imm32 msimg32 shlwapi psapi ws2_32 dbghelp rasapi32 rasdlg iphlpapi uxtheme setupapi t2embed secur32)
+OS_LIBS += $(call EXPAND_LIBNAME,shell32 ole32 version winspool comdlg32 imm32 msimg32 shlwapi psapi ws2_32 dbghelp rasapi32 rasdlg iphlpapi uxtheme setupapi secur32)
 ifdef MOZ_CRASHREPORTER
 OS_LIBS += $(call EXPAND_LIBNAME,wininet)
 endif
 ifdef ACCESSIBILITY
 OS_LIBS += $(call EXPAND_LIBNAME,oleacc)
 endif
 ifdef _MSC_VER
 OS_LIBS += $(call EXPAND_LIBNAME,delayimp)
 EXTRA_DSO_LDOPTS += \
   -DELAYLOAD:gkmedias.dll \
   -DELAYLOAD:psapi.dll \
   -DELAYLOAD:dbghelp.dll \
   -DELAYLOAD:rasapi32.dll \
   -DELAYLOAD:rasdlg.dll \
   -DELAYLOAD:comdlg32.dll \
   -DELAYLOAD:winspool.drv \
-  -DELAYLOAD:t2embed.dll \
   -DELAYLOAD:secur32.dll \
   $(NULL)
 ifdef ACCESSIBILITY
 EXTRA_DSO_LDOPTS += -DELAYLOAD:oleacc.dll
 endif
 endif
 endif # WINNT