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

Side by Side Diff: chrome/child/pdf_child_init.cc

Issue 903583002: Fix GetFontData calling itself repeatedly until the process crashes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/child/pdf_child_init.h" 5 #include "chrome/child/pdf_child_init.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
(...skipping 13 matching lines...) Expand all
24 const void* init_data) { 24 const void* init_data) {
25 DCHECK(std::string("DISPLAY") == std::string(driver_name)); 25 DCHECK(std::string("DISPLAY") == std::string(driver_name));
26 DCHECK(!device_name); 26 DCHECK(!device_name);
27 DCHECK(!output); 27 DCHECK(!output);
28 DCHECK(!init_data); 28 DCHECK(!init_data);
29 29
30 // CreateDC fails behind the sandbox, but not CreateCompatibleDC. 30 // CreateDC fails behind the sandbox, but not CreateCompatibleDC.
31 return CreateCompatibleDC(NULL); 31 return CreateCompatibleDC(NULL);
32 } 32 }
33 33
34 typedef DWORD (WINAPI* GetFontDataPtr) (HDC hdc,
35 DWORD table,
36 DWORD offset,
37 LPVOID buffer,
38 DWORD length);
39 GetFontDataPtr g_original_get_font_data = NULL;
34 static base::win::IATPatchFunction g_iat_patch_get_font_data; 40 static base::win::IATPatchFunction g_iat_patch_get_font_data;
35 DWORD WINAPI GetFontDataPatch(HDC hdc, 41 DWORD WINAPI GetFontDataPatch(HDC hdc,
36 DWORD table, 42 DWORD table,
37 DWORD offset, 43 DWORD offset,
38 LPVOID buffer, 44 LPVOID buffer,
39 DWORD length) { 45 DWORD length) {
40 int rv = GetFontData(hdc, table, offset, buffer, length); 46 int rv = g_original_get_font_data(hdc, table, offset, buffer, length);
41 if (rv == GDI_ERROR && hdc) { 47 if (rv == GDI_ERROR && hdc) {
42 HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT)); 48 HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT));
43 49
44 LOGFONT logfont; 50 LOGFONT logfont;
45 if (GetObject(font, sizeof(LOGFONT), &logfont)) { 51 if (GetObject(font, sizeof(LOGFONT), &logfont)) {
46 std::vector<char> font_data; 52 std::vector<char> font_data;
47 content::ChildThread::Get()->PreCacheFont(logfont); 53 content::ChildThread::Get()->PreCacheFont(logfont);
48 rv = GetFontData(hdc, table, offset, buffer, length); 54 rv = g_original_get_font_data(hdc, table, offset, buffer, length);
49 content::ChildThread::Get()->ReleaseCachedFonts(); 55 content::ChildThread::Get()->ReleaseCachedFonts();
50 } 56 }
51 } 57 }
52 return rv; 58 return rv;
53 } 59 }
54 #endif // OS_WIN 60 #endif // OS_WIN
55 61
56 } // namespace 62 } // namespace
57 63
58 void InitializePDF() { 64 void InitializePDF() {
59 #if defined(OS_WIN) 65 #if defined(OS_WIN)
60 // Need to patch a few functions for font loading to work correctly. This can 66 // Need to patch a few functions for font loading to work correctly. This can
61 // be removed once we switch PDF to use Skia. 67 // be removed once we switch PDF to use Skia.
62 HMODULE current_module = NULL; 68 HMODULE current_module = NULL;
63 wchar_t current_module_name[MAX_PATH]; 69 wchar_t current_module_name[MAX_PATH];
64 CHECK(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, 70 CHECK(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
65 reinterpret_cast<LPCWSTR>(InitializePDF), 71 reinterpret_cast<LPCWSTR>(InitializePDF),
66 &current_module)); 72 &current_module));
67 DWORD result = GetModuleFileNameW(current_module, current_module_name, 73 DWORD result = GetModuleFileNameW(current_module, current_module_name,
68 MAX_PATH); 74 MAX_PATH);
69 if (!result || result == MAX_PATH) 75 if (!result || result == MAX_PATH)
70 return; 76 return;
71 g_iat_patch_createdca.Patch(current_module_name, "gdi32.dll", "CreateDCA", 77 g_iat_patch_createdca.Patch(current_module_name, "gdi32.dll", "CreateDCA",
72 CreateDCAPatch); 78 CreateDCAPatch);
73 g_iat_patch_get_font_data.Patch(current_module_name, "gdi32.dll", 79 g_iat_patch_get_font_data.Patch(current_module_name, "gdi32.dll",
74 "GetFontData", GetFontDataPatch); 80 "GetFontData", GetFontDataPatch);
81 g_original_get_font_data = reinterpret_cast<GetFontDataPtr>(
82 g_iat_patch_get_font_data.original_function());
75 #endif // OS_WIN 83 #endif // OS_WIN
76 } 84 }
77 85
78 } // namespace chrome 86 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698