Skip to content

Commit

Permalink
Fix Windows function patching for PDFium component builds
Browse files Browse the repository at this point in the history
This is necessary for landing [1], which makes PDFium a component.  The previous
reland [2] broke Windows debug builds because InitializePDF() in
pdf_child_init.cc tried to patch chrome.exe instead of (the new) pdfium.dll.
This change makes InitializePDF() patch the correct binary.  Verified this fixes
the Debug build with the PDFium patch applied at [3].

[1] https://pdfium-review.googlesource.com/c/pdfium/+/53910
[2] https://pdfium-review.googlesource.com/c/pdfium/+/53731
[3] https://chromium-review.googlesource.com/c/chromium/src/+/1592280

BUG=chromium:941663
R=thestig

Change-Id: Ief97f62fe4c0dd70c8cbea4b76494906c4205247
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1591662
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657025}
  • Loading branch information
tanderson-google authored and Commit Bot committed May 6, 2019
1 parent ac84c2a commit 008ff43
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions chrome/child/pdf_child_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,24 @@ void InitializePDF() {
// Need to patch a few functions for font loading to work correctly. This can
// be removed once we switch PDF to use Skia
// (https://bugs.chromium.org/p/pdfium/issues/detail?id=11).
HMODULE current_module = CURRENT_MODULE();
#if defined(COMPONENT_BUILD)
HMODULE module = ::GetModuleHandleA("pdfium.dll");

// TODO(thomasanderson): Replace this condition with DCHECK(module) once
// PDFium is switched to a component.
if (!module)
module = CURRENT_MODULE();
#else
HMODULE module = CURRENT_MODULE();
#endif // defined(COMPONENT_BUILD)

static base::NoDestructor<base::win::IATPatchFunction> patch_createdca;
patch_createdca->PatchFromModule(current_module, "gdi32.dll", "CreateDCA",
patch_createdca->PatchFromModule(module, "gdi32.dll", "CreateDCA",
reinterpret_cast<void*>(CreateDCAPatch));

static base::NoDestructor<base::win::IATPatchFunction> patch_get_font_data;
patch_get_font_data->PatchFromModule(
current_module, "gdi32.dll", "GetFontData",
module, "gdi32.dll", "GetFontData",
reinterpret_cast<void*>(GetFontDataPatch));
g_original_get_font_data = reinterpret_cast<GetFontDataPtr>(
patch_get_font_data->original_function());
Expand Down

0 comments on commit 008ff43

Please sign in to comment.