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

Side by Side Diff: net/base/mime_sniffer.cc

Issue 3089004: Mac: Some clang appeasing. (Closed)
Patch Set: '' Created 10 years, 4 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 unified diff | Download patch
« no previous file with comments | « net/base/cookie_monster.cc ('k') | net/http/http_auth_gssapi_posix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Detecting mime types is a tricky business because we need to balance 5 // Detecting mime types is a tricky business because we need to balance
6 // compatibility concerns with security issues. Here is a survey of how other 6 // compatibility concerns with security issues. Here is a survey of how other
7 // browsers behave and then a description of how we intend to behave. 7 // browsers behave and then a description of how we intend to behave.
8 // 8 //
9 // HTML payload, no Content-Type header: 9 // HTML payload, no Content-Type header:
10 // * IE 7: Render as HTML 10 // * IE 7: Render as HTML
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 const size_t len = magic_entry->magic_len; 221 const size_t len = magic_entry->magic_len;
222 222
223 // Keep kBytesRequiredForMagic honest. 223 // Keep kBytesRequiredForMagic honest.
224 DCHECK_LE(len, kBytesRequiredForMagic); 224 DCHECK_LE(len, kBytesRequiredForMagic);
225 225
226 // To compare with magic strings, we need to compute strlen(content), but 226 // To compare with magic strings, we need to compute strlen(content), but
227 // content might not actually have a null terminator. In that case, we 227 // content might not actually have a null terminator. In that case, we
228 // pretend the length is content_size. 228 // pretend the length is content_size.
229 const char* end = 229 const char* end =
230 static_cast<const char*>(memchr(content, '\0', size)); 230 static_cast<const char*>(memchr(content, '\0', size));
231 const size_t content_strlen = (end != NULL) ? (end - content) : size; 231 const size_t content_strlen =
232 (end != NULL) ? static_cast<size_t>(end - content) : size;
232 233
233 bool match = false; 234 bool match = false;
234 if (magic_entry->is_string) { 235 if (magic_entry->is_string) {
235 if (content_strlen >= len) { 236 if (content_strlen >= len) {
236 // String comparisons are case-insensitive 237 // String comparisons are case-insensitive
237 match = (base::strncasecmp(magic_entry->magic, content, len) == 0); 238 match = (base::strncasecmp(magic_entry->magic, content, len) == 0);
238 } 239 }
239 } else { 240 } else {
240 if (size >= len) 241 if (size >= len)
241 match = (memcmp(magic_entry->magic, content, len) == 0); 242 match = (memcmp(magic_entry->magic, content, len) == 0);
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // Now we look in our large table of magic numbers to see if we can find 655 // Now we look in our large table of magic numbers to see if we can find
655 // anything that matches the content. 656 // anything that matches the content.
656 if (SniffForMagicNumbers(content, content_size, 657 if (SniffForMagicNumbers(content, content_size,
657 &have_enough_content, result)) 658 &have_enough_content, result))
658 return true; // We've matched a magic number. No more content needed. 659 return true; // We've matched a magic number. No more content needed.
659 660
660 return have_enough_content; 661 return have_enough_content;
661 } 662 }
662 663
663 } // namespace net 664 } // namespace net
OLDNEW
« no previous file with comments | « net/base/cookie_monster.cc ('k') | net/http/http_auth_gssapi_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698