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

Side by Side Diff: chrome/common/extensions/extension_file_util.cc

Issue 10690016: Check zero-length icon files during extension validation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Included extension #3 Created 8 years, 5 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 | « no previous file | chrome/common/extensions/extension_file_util_unittest.cc » ('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) 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 #include "chrome/common/extensions/extension_file_util.h" 5 #include "chrome/common/extensions/extension_file_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/json/json_file_value_serializer.h" 12 #include "base/json/json_file_value_serializer.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/scoped_temp_dir.h" 16 #include "base/scoped_temp_dir.h"
16 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
17 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
18 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
19 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 223
223 bool ValidateExtension(const Extension* extension, 224 bool ValidateExtension(const Extension* extension,
224 std::string* error, 225 std::string* error,
225 Extension::InstallWarningVector* warnings) { 226 Extension::InstallWarningVector* warnings) {
226 // Validate icons exist. 227 // Validate icons exist.
227 for (ExtensionIconSet::IconMap::const_iterator iter = 228 for (ExtensionIconSet::IconMap::const_iterator iter =
228 extension->icons().map().begin(); 229 extension->icons().map().begin();
229 iter != extension->icons().map().end(); 230 iter != extension->icons().map().end();
230 ++iter) { 231 ++iter) {
231 const FilePath path = extension->GetResource(iter->second).GetFilePath(); 232 const FilePath path = extension->GetResource(iter->second).GetFilePath();
232 if (!file_util::PathExists(path)) { 233 int64 size;
asargent_no_longer_on_chrome 2012/07/03 19:46:49 (pet peeve nit) please initialize |size| to 0
234 if (!file_util::PathExists(path) ||
235 !file_util::GetFileSize(path, &size) ||
236 size == 0) {
233 *error = 237 *error =
234 l10n_util::GetStringFUTF8(IDS_EXTENSION_LOAD_ICON_FAILED, 238 l10n_util::GetStringFUTF8(IDS_EXTENSION_LOAD_ICON_FAILED,
235 UTF8ToUTF16(iter->second)); 239 UTF8ToUTF16(iter->second));
236 return false; 240 return false;
237 } 241 }
238 } 242 }
239 243
240 // Theme resource validation. 244 // Theme resource validation.
241 if (extension->is_theme()) { 245 if (extension->is_theme()) {
242 DictionaryValue* images_value = extension->GetThemeImages(); 246 DictionaryValue* images_value = extension->GetThemeImages();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 const Extension::PluginInfo& plugin = extension->plugins()[i]; 304 const Extension::PluginInfo& plugin = extension->plugins()[i];
301 if (!file_util::PathExists(plugin.path)) { 305 if (!file_util::PathExists(plugin.path)) {
302 *error = 306 *error =
303 l10n_util::GetStringFUTF8( 307 l10n_util::GetStringFUTF8(
304 IDS_EXTENSION_LOAD_PLUGIN_PATH_FAILED, 308 IDS_EXTENSION_LOAD_PLUGIN_PATH_FAILED,
305 plugin.path.LossyDisplayName()); 309 plugin.path.LossyDisplayName());
306 return false; 310 return false;
307 } 311 }
308 } 312 }
309 313
310 // Validate icon location for page actions. 314 // Validate icon location and icon file size for page actions.
311 ExtensionAction* page_action = extension->page_action(); 315 ExtensionAction* page_action = extension->page_action();
312 if (page_action) { 316 if (page_action) {
313 std::vector<std::string> icon_paths(*page_action->icon_paths()); 317 std::vector<std::string> icon_paths(*page_action->icon_paths());
314 if (!page_action->default_icon_path().empty()) 318 if (!page_action->default_icon_path().empty())
315 icon_paths.push_back(page_action->default_icon_path()); 319 icon_paths.push_back(page_action->default_icon_path());
316 for (std::vector<std::string>::iterator iter = icon_paths.begin(); 320 for (std::vector<std::string>::iterator iter = icon_paths.begin();
317 iter != icon_paths.end(); ++iter) { 321 iter != icon_paths.end(); ++iter) {
318 if (!file_util::PathExists(extension->GetResource(*iter).GetFilePath())) { 322 const FilePath& path = extension->GetResource(*iter).GetFilePath();
323 int64 size;
asargent_no_longer_on_chrome 2012/07/03 19:46:49 initialize to 0
324 if (!file_util::PathExists(path) ||
325 !file_util::GetFileSize(path, &size) ||
326 size == 0) {
319 *error = 327 *error =
320 l10n_util::GetStringFUTF8( 328 l10n_util::GetStringFUTF8(
321 IDS_EXTENSION_LOAD_ICON_FOR_PAGE_ACTION_FAILED, 329 IDS_EXTENSION_LOAD_ICON_FOR_PAGE_ACTION_FAILED,
322 UTF8ToUTF16(*iter)); 330 UTF8ToUTF16(*iter));
323 return false; 331 return false;
324 } 332 }
325 } 333 }
326 } 334 }
327 335
328 // Validate icon location for browser actions. 336 // Validate icon location and icon file size for browser actions.
329 // Note: browser actions don't use the icon_paths(). 337 // Note: browser actions don't use the icon_paths().
330 ExtensionAction* browser_action = extension->browser_action(); 338 ExtensionAction* browser_action = extension->browser_action();
331 if (browser_action) { 339 if (browser_action) {
332 std::string path = browser_action->default_icon_path(); 340 std::string path = browser_action->default_icon_path();
333 if (!path.empty() && 341 if (!path.empty()) {
334 !file_util::PathExists(extension->GetResource(path).GetFilePath())) { 342 const FilePath& file_path = extension->GetResource(path).GetFilePath();
343 int64 size;
344 if (!file_util::PathExists(file_path) ||
345 file_util::GetFileSize(file_path, &size) ||
346 size == 0) {
asargent_no_longer_on_chrome 2012/07/03 19:46:49 nit: looks like you have this chunk of "does file
335 *error = 347 *error =
336 l10n_util::GetStringFUTF8( 348 l10n_util::GetStringFUTF8(
337 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, 349 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED,
338 UTF8ToUTF16(path)); 350 UTF8ToUTF16(path));
339 return false; 351 return false;
352 }
340 } 353 }
341 } 354 }
342 355
343 // Validate that background scripts exist. 356 // Validate that background scripts exist.
344 for (size_t i = 0; i < extension->background_scripts().size(); ++i) { 357 for (size_t i = 0; i < extension->background_scripts().size(); ++i) {
345 if (!file_util::PathExists( 358 if (!file_util::PathExists(
346 extension->GetResource( 359 extension->GetResource(
347 extension->background_scripts()[i]).GetFilePath())) { 360 extension->background_scripts()[i]).GetFilePath())) {
348 *error = l10n_util::GetStringFUTF8( 361 *error = l10n_util::GetStringFUTF8(
349 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, 362 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED,
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 return temp_path; 785 return temp_path;
773 786
774 return FilePath(); 787 return FilePath();
775 } 788 }
776 789
777 void DeleteFile(const FilePath& path, bool recursive) { 790 void DeleteFile(const FilePath& path, bool recursive) {
778 file_util::Delete(path, recursive); 791 file_util::Delete(path, recursive);
779 } 792 }
780 793
781 } // namespace extension_file_util 794 } // namespace extension_file_util
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/extension_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698