Skip to content

Commit

Permalink
Bug 1776653 Part 1: Add more crash annotations when font creation hap…
Browse files Browse the repository at this point in the history
…pens. r=jrmuizel

Since we have evidence that CGFontCreate functions can crash, this covers
cases where we might want to know which font was being loaded.

Differential Revision: https://phabricator.services.mozilla.com/D155022
  • Loading branch information
bradwerth committed Aug 29, 2022
1 parent 5c60610 commit 99da320
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions gfx/thebes/gfxMacPlatformFontList.mm
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,10 @@ static bool CheckForAATSmallCaps(CFArrayRef aFeatures) {
if (!cgFont) {
return mHasAATSmallCaps;
}

CrashReporter::AutoAnnotateCrashReport autoFontName(CrashReporter::Annotation::FontName,
FamilyName());

AutoCFRelease<CTFontRef> ctFont = CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr);
if (ctFont) {
AutoCFRelease<CFArrayRef> features = CTFontCopyFeatures(ctFont);
Expand Down Expand Up @@ -1717,6 +1721,9 @@ NS_ConvertUTF16toUTF8 familyNameString(reinterpret_cast<char16_t*>(buffer.Elemen

nsAutoreleasePool localPool;

CrashReporter::AutoAnnotateCrashReport autoFontName(CrashReporter::Annotation::FontName,
aFontName);

NSString* faceName = GetNSStringForString(NS_ConvertUTF8toUTF16(aFontName));

// lookup face based on postscript or full name
Expand Down Expand Up @@ -1782,6 +1789,9 @@ NS_ConvertUTF16toUTF8 familyNameString(reinterpret_cast<char16_t*>(buffer.Elemen
return nullptr;
}

CrashReporter::AutoAnnotateCrashReport autoFontName(CrashReporter::Annotation::FontName,
aFontName);

AutoCFRelease<CGDataProviderRef> provider =
::CGDataProviderCreateWithData(nullptr, aFontData, aLength, &ReleaseData);
AutoCFRelease<CGFontRef> fontRef = ::CGFontCreateWithDataProvider(provider);
Expand Down Expand Up @@ -2029,8 +2039,10 @@ new MacOSFontEntry(aFace->mDescriptor.AsString(SharedFontList()), aFace->mWeight
bool aLoadCmaps) const {
nsAutoreleasePool localPool;

NS_ConvertUTF8toUTF16 name(aFamily->Key().AsString(SharedFontList()));
NSString* family = GetNSStringForString(name);
auto name = aFamily->Key().AsString(SharedFontList());
NSString* family = GetNSStringForString(NS_ConvertUTF8toUTF16(name));

CrashReporter::AutoAnnotateCrashReport autoFontName(CrashReporter::Annotation::FontName, name);

// returns an array of [psname, style name, weight, traits] elements, goofy api
NSArray* fontfaces = [sFontManager availableMembersOfFontFamily:family];
Expand Down

0 comments on commit 99da320

Please sign in to comment.