Chromium Code Reviews| Index: net/base/mime_util.cc |
| diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc |
| index 7db410ba0c9bf636ceee0feeeaf635bfaf7a1bbc..d80c90834c2b920adb5abfb829be6379e0d99a27 100644 |
| --- a/net/base/mime_util.cc |
| +++ b/net/base/mime_util.cc |
| @@ -27,6 +27,12 @@ using std::string; |
| namespace net { |
| +namespace { |
| + |
| +const base::FilePath::CharType kStringTerminator = FILE_PATH_LITERAL('\0'); |
|
eroman
2015/05/18 15:45:24
nit: I think it would be shorter to just inline th
yawano
2015/05/19 02:26:40
Done.
|
| + |
| +} // namespace |
| + |
| // Singleton utility class for mime types. |
| class MimeUtil : public PlatformMimeUtil { |
| public: |
| @@ -164,11 +170,6 @@ class MimeUtil : public PlatformMimeUtil { |
| static base::LazyInstance<MimeUtil>::Leaky g_mime_util = |
| LAZY_INSTANCE_INITIALIZER; |
| -struct MimeInfo { |
| - const char* const mime_type; |
| - const char* const extensions; // comma separated list |
| -}; |
| - |
| static const MimeInfo primary_mappings[] = { |
| { "text/html", "html,htm,shtml,shtm" }, |
| { "text/css", "css" }, |
| @@ -216,12 +217,11 @@ static const MimeInfo secondary_mappings[] = { |
| { "application/pkcs7-mime", "p7m,p7c,p7z" }, |
| { "application/pkcs7-signature", "p7s" }, |
| { "application/x-mpegurl", "m3u8" }, |
| - { "application/epub+zip", "epub" }, |
| }; |
| -static const char* FindMimeType(const MimeInfo* mappings, |
| - size_t mappings_len, |
| - const char* ext) { |
| +const char* FindMimeType(const MimeInfo* mappings, |
| + size_t mappings_len, |
| + const char* ext) { |
| size_t ext_len = strlen(ext); |
| for (size_t i = 0; i < mappings_len; ++i) { |
| @@ -268,6 +268,11 @@ bool MimeUtil::GetMimeTypeFromExtensionHelper( |
| if (ext.length() > kMaxFilePathSize) |
| return false; |
| + // Reject a string which contains null character. |
| + base::FilePath::StringType::size_type nul_pos = ext.find(kStringTerminator); |
|
eroman
2015/05/18 15:45:24
Thanks for adding. I have also filed https://code.
yawano
2015/05/19 02:26:40
Done.
|
| + if (nul_pos != base::FilePath::StringType::npos) |
| + return false; |
| + |
| // We implement the same algorithm as Mozilla for mapping a file extension to |
| // a mime type. That is, we first check a hard-coded list (that cannot be |
| // overridden), and then if not found there, we defer to the system registry. |