From 4f70dd5c954cfcfd55357527da98c15f8355fbe5 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Thu, 15 Apr 2021 17:08:30 -0700 Subject: [PATCH] #642: M1677940 M1698503 M1699835 (modified) --- dom/canvas/CanvasRenderingContext2D.cpp | 36 ++++++++++++++++--------- netwerk/base/nsIOService.cpp | 8 +++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 1974e2b36..6955cd355 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -4030,29 +4030,41 @@ CanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText, gfxFontGroup *CanvasRenderingContext2D::GetCurrentFontStyle() { - // use lazy initilization for the font group since it's rather expensive - if (!CurrentState().fontGroup) { + // Use lazy (re)initialization for the fontGroup since it's rather expensive. + + nsCOMPtr presShell = GetPresShell(); + gfxTextPerfMetrics* tp = nullptr; + if (presShell && !presShell->IsDestroying()) { + tp = presShell->GetPresContext()->GetTextPerfMetrics(); + } + + // If we have a cached fontGroup, check that it is valid for the current + // prescontext; if not, we need to discard and re-create it. + RefPtr& fontGroup = CurrentState().fontGroup; + if (fontGroup && fontGroup->GetTextPerfMetrics() != tp) + fontGroup = nullptr; + + if (!fontGroup) { ErrorResult err; NS_NAMED_LITERAL_STRING(kDefaultFontStyle, "10px sans-serif"); static float kDefaultFontSize = 10.0; - nsCOMPtr presShell = GetPresShell(); - bool fontUpdated = SetFontInternal(kDefaultFontStyle, err); + // If the font has already been set, we're re-creating the fontGroup + // and should re-use the existing font attribute; if not, we initialize + // it to the canvas default. + const nsString& currentFont = CurrentState().font; + bool fontUpdated = SetFontInternal( + currentFont.IsEmpty() ? kDefaultFontStyle : currentFont, err); if (err.Failed() || !fontUpdated) { err.SuppressException(); gfxFontStyle style; style.size = kDefaultFontSize; - gfxTextPerfMetrics* tp = nullptr; - if (presShell && !presShell->IsDestroying()) { - tp = presShell->GetPresContext()->GetTextPerfMetrics(); - } int32_t perDevPixel, perCSSPixel; GetAppUnitsValues(&perDevPixel, &perCSSPixel); gfxFloat devToCssSize = gfxFloat(perDevPixel) / gfxFloat(perCSSPixel); - CurrentState().fontGroup = - gfxPlatform::GetPlatform()->CreateFontGroup(FontFamilyList(eFamily_sans_serif), + fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(FontFamilyList(eFamily_sans_serif), &style, tp, nullptr, devToCssSize); - if (CurrentState().fontGroup) { + if (fontGroup) { CurrentState().font = kDefaultFontStyle; } else { NS_ERROR("Default canvas font is invalid"); @@ -4060,7 +4072,7 @@ gfxFontGroup *CanvasRenderingContext2D::GetCurrentFontStyle() } } - return CurrentState().fontGroup; + return fontGroup; } // diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index 3b8de2b27..d2f7c73d9 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -113,6 +113,7 @@ int16_t gBadPortList[] = { 42, // name 43, // nicname 53, // domain + 69, // tftp 77, // priv-rjs 79, // finger 87, // ttylink @@ -130,8 +131,10 @@ int16_t gBadPortList[] = { 119, // nntp 123, // ntp 135, // loc-srv / epmap + 137, // netbios 139, // netbios 143, // imap2 + 161, // snmp 179, // bgp 389, // ldap 427, // afp (alternate) @@ -154,6 +157,7 @@ int16_t gBadPortList[] = { 636, // ldap+ssl 993, // imap+ssl 995, // pop3+ssl + 1719, // h323gatestat 1720, // h323hostcall 1723, // pptp 2049, // nfs @@ -162,12 +166,14 @@ int16_t gBadPortList[] = { 5060, // sip 5061, // sips 6000, // x11 + 6566, // sane-port 6665, // irc (alternate) 6666, // irc (alternate) 6667, // irc (default) 6668, // irc (alternate) 6669, // irc (alternate) 6697, // irc+tls + 10080, // amanda 0, // Sentinel value: This MUST be zero }; @@ -1182,7 +1188,7 @@ nsIOService::AllowPort(int32_t inPort, const char *scheme, bool *_retval) return NS_OK; } - if (port == 0) { + if (port <= 0 || port >= std::numeric_limits::max()) { *_retval = false; return NS_OK; }