Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: content/common/font_loader_mac.mm

Issue 7655040: Work around a ridiculous bug in ATS, a deprecated system framework (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/app/framework.order ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/font_loader_mac.h" 5 #include "content/common/font_loader_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/mac/mac_util.h" 13 #include "base/mac/mac_util.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 15
16 extern "C" {
17
18 // Work around http://crbug.com/93191, a really nasty memory smasher bug.
19 // On Mac OS X 10.7 ("Lion"), ATS writes to memory it doesn't own.
20 // SendDeactivateFontsInContainerMessage, called by ATSFontDeactivate,
21 // may trash memory whenever dlsym(RTLD_DEFAULT,
22 // "_CTFontManagerUnregisterFontForData") returns NULL. In that case, it tries
23 // to locate that symbol in the CoreText framework, doing some extremely
24 // sloppy string handling resulting in a likelihood that the string
25 // "Text.framework/Versions/A/CoreText" will be written over memory that it
26 // doesn't own. The kicker here is that Apple dlsym always inserts its own
27 // leading underscore, so ATS actually winds up looking up a
28 // __CTFontManagerUnregisterFontForData symbol, which doesn't even exist in
29 // CoreText. It's only got the single-underscore variant corresponding to an
30 // underscoreless extern "C" name.
31 //
32 // Providing a single-underscored extern "C" function by this name results in
33 // a __CTFontManagerUnregisterFontForData symbol that, as long as it's public
34 // (not private extern) and unstripped, ATS will find. If it finds it, it
35 // avoids making amateur string mistakes that ruin everyone else's good time.
36 //
37 // Since ATS wouldn't normally be able to call this function anyway, it's just
38 // left as a no-op here.
39 //
40 // This file seems as good as any other to place this function. It was chosen
41 // because it already interfaces with ATS for other reasons.
42 //
43 // SendDeactivateFontsInContainerMessage on 10.6 ("Snow Leopard") appears to
44 // share this bug but this sort of memory corruption wasn't detected until
45 // 10.7. The implementation in 10.5 ("Leopard") does not have this problem.
46 __attribute__((visibility("default")))
47 void _CTFontManagerUnregisterFontForData(NSUInteger, int) {
48 }
49
50 } // extern "C"
51
16 // static 52 // static
17 bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode, 53 bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
18 base::SharedMemory* font_data, 54 base::SharedMemory* font_data,
19 uint32* font_data_size, 55 uint32* font_data_size,
20 uint32* font_id) { 56 uint32* font_id) {
21 CHECK(font_data); 57 CHECK(font_data);
22 CHECK(font_data_size); 58 CHECK(font_data_size);
23 CHECK(font_id); 59 CHECK(font_id);
24 *font_data_size = 0; 60 *font_data_size = 0;
25 *font_id = 0; 61 *font_id = 0;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // This is the value used by WebKit when activating remote fonts. 153 // This is the value used by WebKit when activating remote fonts.
118 const ATSFontContext kFontContextPrivate = 3; 154 const ATSFontContext kFontContextPrivate = 3;
119 OSStatus err = ATSFontActivateFromMemory(shm.memory(), font_data_size, 155 OSStatus err = ATSFontActivateFromMemory(shm.memory(), font_data_size,
120 kFontContextPrivate, kATSFontFormatUnspecified, NULL, 156 kFontContextPrivate, kATSFontFormatUnspecified, NULL,
121 kATSOptionFlagsDefault, font_container); 157 kATSOptionFlagsDefault, font_container);
122 if (err != noErr || !font_container) 158 if (err != noErr || !font_container)
123 return false; 159 return false;
124 160
125 return true; 161 return true;
126 } 162 }
OLDNEW
« no previous file with comments | « chrome/app/framework.order ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698