Bug 1435859 - Fix OOM crash on filenames without extensions. r=gcp, a=RyanVM
authorFrancois Marier <francois@mozilla.com>
Thu, 15 Feb 2018 12:30:40 -0800
changeset 455012 17c5d6591ddef2166d1fe7785d9f9f859e79ac98
parent 455011 4c965e8fc803b9eff98c9bfa57c7f238ba8c92e9
child 455013 575e33458d1b599df7d5ac28f25fafe3b3e38cee
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp, RyanVM
bugs1435859
milestone59.0
Bug 1435859 - Fix OOM crash on filenames without extensions. r=gcp, a=RyanVM Passing a value of -1 to nsCString::Truncate() converts that value to a large integer and leads to an unnecessary 4GB memory allocation. MozReview-Commit-ID: Icm5iUsEgA6
toolkit/components/url-classifier/Classifier.cpp
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -354,18 +354,23 @@ Classifier::DeleteTables(nsIFile* aDirec
       DeleteTables(file, aTables);
       continue;
     }
 
     nsCString leafName;
     rv = file->GetNativeLeafName(leafName);
     NS_ENSURE_SUCCESS_VOID(rv);
 
-    leafName.Truncate(leafName.RFind("."));
-    if (aTables.Contains(leafName)) {
+    // Remove file extension if there's one.
+    int32_t dotPosition = leafName.RFind(".");
+    if (dotPosition >= 0) {
+      leafName.Truncate(dotPosition);
+    }
+
+    if (!leafName.IsEmpty() && aTables.Contains(leafName)) {
       if (NS_FAILED(file->Remove(false))) {
         NS_WARNING(nsPrintfCString("Fail to remove file %s from the disk",
                                    leafName.get()).get());
       }
     }
   }
   NS_ENSURE_SUCCESS_VOID(rv);
 }