summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-12 03:19:12 +0000
committerfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-12 03:19:12 +0000
commit30caf4ffacca9a808417de827e077991d2782d41 (patch)
treef7d3d186462c97806aecc8cf7aec9f84f9d206e4 /net
parent493675cb47dc7d7f297e2ec5e5b80510af087ce7 (diff)
downloadchromium_src-30caf4ffacca9a808417de827e077991d2782d41.zip
chromium_src-30caf4ffacca9a808417de827e077991d2782d41.tar.gz
chromium_src-30caf4ffacca9a808417de827e077991d2782d41.tar.bz2
replace memcmp with MagicCmp that supports '.' for single character of anything and add webp
BUG=67987 TEST=omnibox can show webp from filer or harddrive when mimetype or extension is wrong Review URL: http://codereview.chromium.org/6124007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71141 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/mime_sniffer.cc22
1 files changed, 19 insertions, 3 deletions
diff --git a/net/base/mime_sniffer.cc b/net/base/mime_sniffer.cc
index 1a52b99..bd16462f 100644
--- a/net/base/mime_sniffer.cc
+++ b/net/base/mime_sniffer.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -146,6 +146,8 @@ static const MagicNumber kMagicNumbers[] = {
MAGIC_NUMBER("image/tiff", "II*")
MAGIC_NUMBER("image/tiff", "MM\x00*")
MAGIC_NUMBER("audio/mpeg", "ID3")
+ MAGIC_NUMBER("image/webp", "RIFF....WEBPVP8 ")
+ MAGIC_NUMBER("video/webm", "\x1A\x45\xDF\xA3")
// TODO(abarth): we don't handle partial byte matches yet
// MAGIC_NUMBER("video/mpeg", "\x00\x00\x01\xB")
// MAGIC_NUMBER("audio/mpeg", "\xFF\xE")
@@ -215,6 +217,19 @@ static scoped_refptr<base::Histogram> UMASnifferHistogramGet(const char* name,
return counter;
}
+// Compare content header to a magic number where magic_entry can contain '.'
+// for single character of anything, allowing some bytes to be skipped.
+static bool MagicCmp(const char* magic_entry, const char* content, size_t len) {
+ while (len) {
+ if ((*magic_entry != '.') && (*magic_entry != *content))
+ return false;
+ ++magic_entry;
+ ++content;
+ --len;
+ }
+ return true;
+}
+
static bool MatchMagicNumber(const char* content, size_t size,
const MagicNumber* magic_entry,
std::string* result) {
@@ -239,7 +254,7 @@ static bool MatchMagicNumber(const char* content, size_t size,
}
} else {
if (size >= len)
- match = (memcmp(magic_entry->magic, content, len) == 0);
+ match = MagicCmp(magic_entry->magic, content, len);
}
if (match) {
@@ -251,7 +266,8 @@ static bool MatchMagicNumber(const char* content, size_t size,
static bool CheckForMagicNumbers(const char* content, size_t size,
const MagicNumber* magic, size_t magic_len,
- base::Histogram* counter, std::string* result) {
+ base::Histogram* counter,
+ std::string* result) {
for (size_t i = 0; i < magic_len; ++i) {
if (MatchMagicNumber(content, size, &(magic[i]), result)) {
if (counter) counter->Add(static_cast<int>(i));