summaryrefslogtreecommitdiffstats
path: root/chrome/utility/extensions/unpacker.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/utility/extensions/unpacker.cc')
-rw-r--r--chrome/utility/extensions/unpacker.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/chrome/utility/extensions/unpacker.cc b/chrome/utility/extensions/unpacker.cc
index f2c6727..caeaf6e 100644
--- a/chrome/utility/extensions/unpacker.cc
+++ b/chrome/utility/extensions/unpacker.cc
@@ -12,6 +12,7 @@
#include "base/i18n/rtl.h"
#include "base/json/json_file_value_serializer.h"
#include "base/memory/scoped_handle.h"
+#include "base/safe_numerics.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h"
@@ -85,6 +86,13 @@ bool PathContainsParentDirectory(const base::FilePath& path) {
return false;
}
+bool WritePickle(const IPC::Message& pickle, const base::FilePath& dest_path) {
+ int size = base::checked_numeric_cast<int>(pickle.size());
+ const char* data = static_cast<const char*>(pickle.data());
+ int bytes_written = file_util::WriteFile(dest_path, data, size);
+ return (bytes_written == size);
+}
+
} // namespace
struct Unpacker::InternalData {
@@ -228,8 +236,7 @@ bool Unpacker::DumpImagesToFile() {
base::FilePath path = extension_path_.DirName().AppendASCII(
kDecodedImagesFilename);
- if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()),
- pickle.size())) {
+ if (!WritePickle(pickle, path)) {
SetError("Could not write image data to disk.");
return false;
}
@@ -243,8 +250,7 @@ bool Unpacker::DumpMessageCatalogsToFile() {
base::FilePath path = extension_path_.DirName().AppendASCII(
kDecodedMessageCatalogsFilename);
- if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()),
- pickle.size())) {
+ if (!WritePickle(pickle, path)) {
SetError("Could not write message catalogs to disk.");
return false;
}