Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Unified Diff: net/base/mime_sniffer.cc

Issue 6124007: replace memcmp with MagicCmp that supports '.' for single character of anythi... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/mime_sniffer.cc
===================================================================
--- net/base/mime_sniffer.cc (revision 70720)
+++ net/base/mime_sniffer.cc (working copy)
@@ -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,21 @@
return counter;
}
+static bool MagicCmp(const char* magic_entry, const char* content, size_t len) {
+ bool same = true;
+ while (len && same) {
+ if (!*content && !magic_entry) {
Tom Finegan 2011/01/11 18:51:11 I think you want !*magic_entry here; at least if y
fbarchard1 2011/01/11 19:20:11 Done.
+ break;
+ same = (*magic_entry == *content) || (*magic_entry == '.' && *content);
+ if (!*content || !magic_entry)
Tom Finegan 2011/01/11 18:51:11 !*magic_entry again, assuming I'm correct above an
fbarchard1 2011/01/11 19:20:11 Done.
+ 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 +256,7 @@
}
} else {
if (size >= len)
- match = (memcmp(magic_entry->magic, content, len) == 0);
+ match = MagicCmp(magic_entry->magic, content, len);
Tom Finegan 2011/01/11 18:51:11 Not that I have any major issue with being more sp
fbarchard1 2011/01/11 19:20:11 Done. Added comments
}
if (match) {
@@ -251,7 +268,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));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698