Index: net/base/mime_sniffer.cc |
=================================================================== |
--- net/base/mime_sniffer.cc (revision 70720) |
+++ net/base/mime_sniffer.cc (working copy) |
@@ -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 @@ |
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,23 @@ |
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) { |
+ bool same = true; |
+ while (len && same) { |
+ if (!*content && !*magic_entry) |
abarth-chromium
2011/01/11 19:51:29
I don't think this is correct. We want to match n
fbarchard1
2011/01/11 19:57:39
I think its correct. If both strings have been th
Avi (use Gerrit)
2011/01/11 20:00:02
Given this argument between you two, I think it's
|
+ break; |
+ same = (*magic_entry == *content) || (*magic_entry == '.' && *content); |
+ if (!*content || !*magic_entry) |
+ break; |
+ ++magic_entry; |
+ ++content; |
+ --len; |
+ } |
+ return same; |
+} |
+ |
static bool MatchMagicNumber(const char* content, size_t size, |
const MagicNumber* magic_entry, |
std::string* result) { |
@@ -239,7 +258,7 @@ |
} |
} else { |
if (size >= len) |
- match = (memcmp(magic_entry->magic, content, len) == 0); |
+ match = MagicCmp(magic_entry->magic, content, len); |
} |
if (match) { |
@@ -251,7 +270,8 @@ |
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)); |