Commit bb566bc4 authored by Arthur Edelstein's avatar Arthur Edelstein Committed by Georg Koppen
Browse files

Bug #13313: Pref 'font.system.whitelist' restricts set of permitted fonts

parent d5e200f0
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1146,6 +1146,10 @@ gfxDWriteFontList::GetFontsFromCollection(IDWriteFontCollection* aCollection)

        nsDependentString familyName(enName.Elements());

        if (!gfxFontUtils::IsFontFamilyNameAllowed(familyName)) {
            continue;
        }

        fam = new gfxDWriteFontFamily(familyName, family);
        if (!fam) {
            continue;
+15 −13
Original line number Diff line number Diff line
@@ -1044,7 +1044,7 @@ gfxFT2FontList::AddFaceToList(const nsCString& aEntryName, uint32_t aIndex,
        NS_ConvertUTF8toUTF16 name(aFace->family_name);
        BuildKeyNameFromFontName(name);
        gfxFontFamily *family = fontFamilies.GetWeak(name);
        if (!family) {
        if (!family && gfxFontUtils::IsFontFamilyNameAllowed(name)) {
            family = new FT2FontFamily(name);
            fontFamilies.Put(name, family);
            if (mSkipSpaceLookupCheckFamilies.Contains(name)) {
@@ -1315,6 +1315,7 @@ gfxFT2FontList::AppendFaceFromFontListEntry(const FontListEntry& aFLE,
            aFLE.isHidden() ? mHiddenFontFamilies : mFontFamilies;
        fe->mStandardFace = (aStdFile == kStandard);
        nsAutoString name(aFLE.familyName());
        if (gfxFontUtils::IsFontFamilyNameAllowed(name)) {
            gfxFontFamily *family = fontFamilies.GetWeak(name);
            if (!family) {
                family = new FT2FontFamily(name);
@@ -1331,6 +1332,7 @@ gfxFT2FontList::AppendFaceFromFontListEntry(const FontListEntry& aFLE,
            fe->CheckForBrokenFont(family);
        }
    }
}

static PLDHashOperator
AddFamilyToFontList(nsStringHashKey::KeyType aKey,
+25 −0
Original line number Diff line number Diff line
@@ -1771,3 +1771,28 @@ gfxFontUtils::IsCffFont(const uint8_t* aFontData)

#endif

/* static */
nsTHashtable<nsStringHashKey>* gfxFontUtils::sWhitelistFamilyNames = nullptr;

/* static */
bool
gfxFontUtils::IsFontFamilyNameAllowed(const nsAString& aFontFamilyName)
{
    if (!sWhitelistFamilyNames) {
        sWhitelistFamilyNames = new nsTHashtable<nsStringHashKey>();
        nsAutoTArray<nsString, 10> list;
        GetPrefsFontList("font.system.whitelist", list);
        uint32_t numFonts = list.Length();
        for (uint32_t i = 0; i < numFonts; i++) {
            nsAutoString key;
            ToLowerCase(list[i], key);
            sWhitelistFamilyNames->PutEntry(key);
        }
    }
    nsAutoString fontFamilyNameLower;
    ToLowerCase(aFontFamilyName, fontFamilyNameLower);
    // If whitelist is empty, any family name is allowed. If whitelist
    // has entries, then only allow family names in the whitelist.
    return sWhitelistFamilyNames->Count() == 0 ||
           sWhitelistFamilyNames->Contains(fontFamilyNameLower);
}
+11 −0
Original line number Diff line number Diff line

/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -9,6 +10,8 @@
#include "gfxPlatform.h"
#include "nsComponentManagerUtils.h"
#include "nsTArray.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"
#include "nsAutoPtr.h"
#include "mozilla/Likely.h"
#include "mozilla/Endian.h"
@@ -971,6 +974,14 @@ public:
                                    nsTArray<uint16_t> &aGlyphs,
                                    nsTArray<mozilla::gfx::Color> &aColors);

    // A list of white-listed system fonts. If the list is empty, we permit
    // all fonts.
    static nsTHashtable<nsStringHashKey>* sWhitelistFamilyNames;

    // Returns true only if the font family name is whitelisted or the
    // whitelist is empty.
    static bool IsFontFamilyNameAllowed(const nsAString& aFontFamilyName);

protected:
    friend struct MacCharsetMappingComparator;

+1 −1
Original line number Diff line number Diff line
@@ -697,7 +697,7 @@ gfxGDIFontList::EnumFontFamExProc(ENUMLOGFONTEXW *lpelfe,

    gfxGDIFontList *fontList = PlatformFontList();

    if (!fontList->mFontFamilies.GetWeak(name)) {
    if (gfxFontUtils::IsFontFamilyNameAllowed(name) && !fontList->mFontFamilies.GetWeak(name)) {
        nsDependentString faceName(lf.lfFaceName);
        nsRefPtr<gfxFontFamily> family = new GDIFontFamily(faceName);
        fontList->mFontFamilies.Put(name, family);
Loading