Bug 1212600 - No upper limit on digest256 list file size. r=francois draft
authordimi <dlee@mozilla.com>
Mon, 28 Mar 2016 15:10:03 +0800
changeset 345205 78c36395f4793ef4d81c052e0dc8dd03023ab7c8
parent 344639 d5f3da0cfe7ccf846c354014c9b059fad6ba0de5
child 517125 872c757d2713820b0ad5ede9d36ad2dfbfec4ef2
push id14015
push userdlee@mozilla.com
push dateMon, 28 Mar 2016 07:11:00 +0000
reviewersfrancois
bugs1212600
milestone48.0a1
Bug 1212600 - No upper limit on digest256 list file size. r=francois MozReview-Commit-ID: b1aQbF92as
toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
--- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
@@ -20,16 +20,19 @@
 #include "mozilla/Logging.h"
 #include "nsIInterfaceRequestor.h"
 #include "mozilla/LoadContext.h"
 #include "mozilla/Telemetry.h"
 #include "nsContentUtils.h"
 
 static const char* gQuitApplicationMessage = "quit-application";
 
+// Limit the list file size to 32mb
+const uint32_t MAX_FILE_SIZE = (32 * 1024 * 1024);
+
 #undef LOG
 
 // NSPR_LOG_MODULES=UrlClassifierStreamUpdater:5
 static mozilla::LazyLogModule gUrlClassifierStreamUpdaterLog("UrlClassifierStreamUpdater");
 #define LOG(args) MOZ_LOG(gUrlClassifierStreamUpdaterLog, mozilla::LogLevel::Debug, args)
 
 // This class does absolutely nothing, except pass requests onto the DBService.
 
@@ -639,16 +642,21 @@ nsUrlClassifierStreamUpdater::OnDataAvai
                                               uint64_t aSourceOffset,
                                               uint32_t aLength)
 {
   if (!mDBService)
     return NS_ERROR_NOT_INITIALIZED;
 
   LOG(("OnDataAvailable (%d bytes)", aLength));
 
+  if (aSourceOffset > MAX_FILE_SIZE) {
+    LOG(("OnDataAvailable::Abort because exceeded the maximum file size(%lld)", aSourceOffset));
+    return NS_ERROR_FILE_TOO_BIG;
+  }
+
   nsresult rv;
 
   // Copy the data into a nsCString
   nsCString chunk;
   rv = NS_ConsumeStream(aIStream, aLength, chunk);
   NS_ENSURE_SUCCESS(rv, rv);
 
   //LOG(("Chunk (%d): %s\n\n", chunk.Length(), chunk.get()));