Bug 1407056: Follow-up: Don't try to truncate data URI strings to a longer length. r=me
authorKris Maglione <maglione.k@gmail.com>
Thu, 12 Oct 2017 16:56:37 -0700
changeset 386037 ef7ff96cd4d0fd465a7b94925358558764867c03
parent 386036 d480c295d4eb093b1890056cc724e12bda7ac3ca
child 386038 a097a0f0b84006530ceffbee1ebbe0bf91f8c83c
push id32673
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 09:13:17 +0000
treeherdermozilla-central@196dadb2fe50 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1407056
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1407056: Follow-up: Don't try to truncate data URI strings to a longer length. r=me MozReview-Commit-ID: CDsYXyrhB7T
dom/security/nsCSPContext.cpp
--- a/dom/security/nsCSPContext.cpp
+++ b/dom/security/nsCSPContext.cpp
@@ -1131,21 +1131,23 @@ class CSPReportSenderRunnable final : pu
       nsCOMPtr<nsIURI> blockedURI = do_QueryInterface(mBlockedContentSource);
       // if mBlockedContentSource is not a URI, it could be a string
       nsCOMPtr<nsISupportsCString> blockedString = do_QueryInterface(mBlockedContentSource);
 
       nsCString blockedDataStr;
 
       if (blockedURI) {
         blockedURI->GetSpec(blockedDataStr);
-        bool isData = false;
-        rv = blockedURI->SchemeIs("data", &isData);
-        if (NS_SUCCEEDED(rv) && isData) {
-          blockedDataStr.Truncate(40);
-          blockedDataStr.AppendASCII("...");
+        if (blockedDataStr.Length() > 40) {
+          bool isData = false;
+          rv = blockedURI->SchemeIs("data", &isData);
+          if (NS_SUCCEEDED(rv) && isData) {
+            blockedDataStr.Truncate(40);
+            blockedDataStr.AppendASCII("...");
+          }
         }
       } else if (blockedString) {
         blockedString->GetData(blockedDataStr);
       }
 
       if (blockedDataStr.Length() > 0) {
         nsString blockedDataChar16 = NS_ConvertUTF8toUTF16(blockedDataStr);
         const char16_t* params[] = { mViolatedDirective.get(),