Bug 1212600 - No upper limit on digest256 list file size. r=francois
MozReview-Commit-ID: b1aQbF92as
--- 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()));