Bug 739040 - Use the length of the decoded string, if no more than 512 bytes, to sniff for feeds; r=Mano a=blocking
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 20 Apr 2012 13:03:53 -0400
changeset 95355 38110d3443632522753427617ca3db566b1d75a5
parent 95354 7dc2085a8cc6f913f3c76a2b5388c23a11223724
child 95356 f1d0e75d425aae16eede355eaf00996c1d698d65
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMano, blocking
bugs739040
milestone14.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 739040 - Use the length of the decoded string, if no more than 512 bytes, to sniff for feeds; r=Mano a=blocking
browser/components/feeds/src/nsFeedSniffer.cpp
--- a/browser/components/feeds/src/nsFeedSniffer.cpp
+++ b/browser/components/feeds/src/nsFeedSniffer.cpp
@@ -64,17 +64,17 @@
 
 #define TYPE_ATOM "application/atom+xml"
 #define TYPE_RSS "application/rss+xml"
 #define TYPE_MAYBE_FEED "application/vnd.mozilla.maybe.feed"
 
 #define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 #define NS_RSS "http://purl.org/rss/1.0/"
 
-#define MAX_BYTES 512
+#define MAX_BYTES 512u
 
 NS_IMPL_ISUPPORTS3(nsFeedSniffer,
                    nsIContentSniffer,
                    nsIStreamListener,
                    nsIRequestObserver)
 
 nsresult
 nsFeedSniffer::ConvertEncodedData(nsIRequest* request,
@@ -319,18 +319,19 @@ nsFeedSniffer::GetMIMETypeFromContent(ns
 
   // The strategy here is based on that described in:
   // http://blogs.msdn.com/rssteam/articles/PublishersGuide.aspx
   // for interoperarbility purposes.
 
   // We cap the number of bytes to scan at MAX_BYTES to prevent picking up 
   // false positives by accidentally reading document content, e.g. a "how to
   // make a feed" page.
-  if (length > MAX_BYTES)
-    length = MAX_BYTES;
+  if (!mDecodedData.IsEmpty()) {
+    length = NS_MIN(mDecodedData.Length(), MAX_BYTES);
+  }
 
   // Thus begins the actual sniffing.
   nsDependentCSubstring dataString((const char*)testData, length);
 
   bool isFeed = false;
 
   // RSS 0.91/0.92/2.0
   isFeed = ContainsTopLevelSubstring(dataString, "<rss");