OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 size_t magic_len; | 115 size_t magic_len; |
116 bool is_string; | 116 bool is_string; |
117 const char* mask; // if set, must have same length as |magic| | 117 const char* mask; // if set, must have same length as |magic| |
118 }; | 118 }; |
119 | 119 |
120 #define MAGIC_NUMBER(mime_type, magic) \ | 120 #define MAGIC_NUMBER(mime_type, magic) \ |
121 { (mime_type), (magic), sizeof(magic)-1, false, NULL }, | 121 { (mime_type), (magic), sizeof(magic)-1, false, NULL }, |
122 | 122 |
123 template <int MagicSize, int MaskSize> | 123 template <int MagicSize, int MaskSize> |
124 class VerifySizes { | 124 class VerifySizes { |
125 COMPILE_ASSERT(MagicSize == MaskSize, sizes_must_be_equal); | 125 static_assert(MagicSize == MaskSize, "sizes must be equal"); |
| 126 |
126 public: | 127 public: |
127 enum { SIZES = MagicSize }; | 128 enum { SIZES = MagicSize }; |
128 }; | 129 }; |
129 | 130 |
130 #define verified_sizeof(magic, mask) \ | 131 #define verified_sizeof(magic, mask) \ |
131 VerifySizes<sizeof(magic), sizeof(mask)>::SIZES | 132 VerifySizes<sizeof(magic), sizeof(mask)>::SIZES |
132 | 133 |
133 #define MAGIC_MASK(mime_type, magic, mask) \ | 134 #define MAGIC_MASK(mime_type, magic, mask) \ |
134 { (mime_type), (magic), verified_sizeof(magic, mask)-1, false, (mask) }, | 135 { (mime_type), (magic), verified_sizeof(magic, mask)-1, false, (mask) }, |
135 | 136 |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 // First check the extra table. | 964 // First check the extra table. |
964 if (CheckForMagicNumbers(content, size, kExtraMagicNumbers, | 965 if (CheckForMagicNumbers(content, size, kExtraMagicNumbers, |
965 arraysize(kExtraMagicNumbers), NULL, result)) | 966 arraysize(kExtraMagicNumbers), NULL, result)) |
966 return true; | 967 return true; |
967 // Finally check the original table. | 968 // Finally check the original table. |
968 return CheckForMagicNumbers(content, size, kMagicNumbers, | 969 return CheckForMagicNumbers(content, size, kMagicNumbers, |
969 arraysize(kMagicNumbers), NULL, result); | 970 arraysize(kMagicNumbers), NULL, result); |
970 } | 971 } |
971 | 972 |
972 } // namespace net | 973 } // namespace net |
OLD | NEW |