set_svgimage_page_after_document_install.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Fredrik=20S=C3=B6derqvist?= <[email protected]>
  3. Date: Fri, 9 Jul 2021 08:44:55 +0000
  4. Subject: Set SVGImage::page_ after document install
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. We can end up having the associated ImageResource call
  9. SVGImage::ResetAnimation() before the Document has been associated with
  10. the SVGImage's LocalFrame, but after the link to the initial Document
  11. was severed, if a GC is triggered within that window and ends up
  12. collecting the last observer of the ImageResource.
  13. By assigning |SVGImage::page_| after the installing the document, we
  14. close this hole since SVGImage::RootElement() (called by
  15. SVGImage::ResetAnimation()) will now observe a null Page and return null
  16. without attempting to dereference the document.
  17. Bug: 1216190
  18. Change-Id: I26e08848e5b9bd52e3377841eee35e4acc03d320
  19. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3010140
  20. Reviewed-by: Stephen Chenney <[email protected]>
  21. Commit-Queue: Fredrik Söderquist <[email protected]>
  22. Cr-Commit-Position: refs/heads/master@{#899922}
  23. diff --git a/third_party/blink/renderer/core/svg/graphics/svg_image.cc b/third_party/blink/renderer/core/svg/graphics/svg_image.cc
  24. index b23ad2192bec4d1cac9d704074d12c9e00d4d2f5..ff2bf69be27f0afcb6a9909e716495e8d4a127ef 100644
  25. --- a/third_party/blink/renderer/core/svg/graphics/svg_image.cc
  26. +++ b/third_party/blink/renderer/core/svg/graphics/svg_image.cc
  27. @@ -851,12 +851,15 @@ Image::SizeAvailability SVGImage::DataChanged(bool all_data_received) {
  28. // SVG Images are transparent.
  29. frame->View()->SetBaseBackgroundColor(Color::kTransparent);
  30. - page_ = page;
  31. -
  32. TRACE_EVENT0("blink", "SVGImage::dataChanged::load");
  33. frame->ForceSynchronousDocumentInstall("image/svg+xml", Data());
  34. + // Set up our Page reference after installing our document. This avoids
  35. + // tripping on a non-existing (null) Document if a GC is triggered during the
  36. + // set up and ends up collecting the last owner/observer of this image.
  37. + page_ = page;
  38. +
  39. // Intrinsic sizing relies on computed style (e.g. font-size and
  40. // writing-mode).
  41. frame->GetDocument()->UpdateStyleAndLayoutTree();