Bug 1174811 - Part 2: Limit favicon downloads to 1MB. r=froydnj
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Wed, 17 Jun 2015 06:38:22 -0700
changeset 249349 8861436c0ddb1cc6115cb639bdae1ac3e24f9b5f
parent 249348 47caf1b25775bdedd2e7869755f6fbafd27cab29
child 249350 feb7cd25aafb27c55a24226c65e2aada2b3c3338
push id28923
push userryanvm@gmail.com
push dateWed, 17 Jun 2015 18:57:11 +0000
treeherdermozilla-central@099d6cd6725e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1174811
milestone41.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 1174811 - Part 2: Limit favicon downloads to 1MB. r=froydnj
toolkit/components/places/AsyncFaviconHelpers.cpp
--- a/toolkit/components/places/AsyncFaviconHelpers.cpp
+++ b/toolkit/components/places/AsyncFaviconHelpers.cpp
@@ -577,16 +577,22 @@ AsyncFetchAndSetIconFromNetwork::OnStart
 
 NS_IMETHODIMP
 AsyncFetchAndSetIconFromNetwork::OnDataAvailable(nsIRequest* aRequest,
                                                  nsISupports* aContext,
                                                  nsIInputStream* aInputStream,
                                                  uint64_t aOffset,
                                                  uint32_t aCount)
 {
+  const size_t kMaxFaviconDownloadSize = 1 * 1024 * 1024;
+  if (mIcon.data.Length() + aCount > kMaxFaviconDownloadSize) {
+    mIcon.data.Truncate();
+    return NS_ERROR_FILE_TOO_BIG;
+  }
+
   nsAutoCString buffer;
   nsresult rv = NS_ConsumeStream(aInputStream, aCount, buffer);
   if (rv != NS_BASE_STREAM_WOULD_BLOCK && NS_FAILED(rv)) {
     return rv;
   }
 
   if (!mIcon.data.Append(buffer, fallible)) {
     mIcon.data.Truncate();