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

Unified Diff: courgette/third_party/bsdiff/bsdiff_apply.cc

Issue 2534873005: Sandbox the component updater's patcher utility process. (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: courgette/third_party/bsdiff/bsdiff_apply.cc
diff --git a/courgette/third_party/bsdiff/bsdiff_apply.cc b/courgette/third_party/bsdiff/bsdiff_apply.cc
index fca9616a8ab0bf62a29ef6f1a8dc62ab59a0988b..f5c105a9088d5eeae726c25181d96f3b07e141f5 100644
--- a/courgette/third_party/bsdiff/bsdiff_apply.cc
+++ b/courgette/third_party/bsdiff/bsdiff_apply.cc
@@ -40,6 +40,7 @@
#include <stddef.h>
#include <stdint.h>
+#include "base/files/file.h"
#include "base/files/memory_mapped_file.h"
#include "courgette/crc.h"
#include "courgette/streams.h"
@@ -192,21 +193,38 @@ BSDiffStatus ApplyBinaryPatch(SourceStream* old_stream,
BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_file_path,
const base::FilePath& patch_file_path,
const base::FilePath& new_file_path) {
+ return ApplyBinaryPatch(
+ base::File(
+ base::FilePath(old_file_path),
+ base::File::FLAG_OPEN | base::File::FLAG_READ),
+ base::File(
+ base::FilePath(patch_file_path),
+ base::File::FLAG_OPEN | base::File::FLAG_READ),
+ base::File(
+ base::FilePath(new_file_path),
+ base::File::FLAG_CREATE_ALWAYS |
+ base::File::FLAG_WRITE |
+ base::File::FLAG_EXCLUSIVE_WRITE));
+}
+
+BSDiffStatus ApplyBinaryPatch(base::File old_file,
+ base::File patch_file,
+ base::File new_file) {
// Set up the old stream.
- base::MemoryMappedFile old_file;
- if (!old_file.Initialize(old_file_path)) {
+ base::MemoryMappedFile old_file_mem;
+ if (!old_file_mem.Initialize(std::move(old_file))) {
return READ_ERROR;
}
SourceStream old_file_stream;
- old_file_stream.Init(old_file.data(), old_file.length());
+ old_file_stream.Init(old_file_mem.data(), old_file_mem.length());
// Set up the patch stream.
- base::MemoryMappedFile patch_file;
- if (!patch_file.Initialize(patch_file_path)) {
+ base::MemoryMappedFile patch_file_mem;
+ if (!patch_file_mem.Initialize(std::move(patch_file))) {
return READ_ERROR;
}
SourceStream patch_file_stream;
- patch_file_stream.Init(patch_file.data(), patch_file.length());
+ patch_file_stream.Init(patch_file_mem.data(), patch_file_mem.length());
// Set up the new stream and apply the patch.
SinkStream new_sink_stream;
@@ -217,8 +235,9 @@ BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_file_path,
}
// Write the stream to disk.
huangs 2016/12/06 18:23:22 There seems to be a change in behavior: Previously
waffles 2016/12/06 19:18:45 Yes, that is correct. This can't be avoided in the
huangs 2016/12/06 19:40:07 This is not an issue for Component Updator, but it
waffles 2016/12/06 19:46:22 Sounds good, will do.
- int written = base::WriteFile(
- new_file_path, reinterpret_cast<const char*>(new_sink_stream.Buffer()),
+ int written = new_file.Write(
+ 0,
+ reinterpret_cast<const char*>(new_sink_stream.Buffer()),
static_cast<int>(new_sink_stream.Length()));
if (written != static_cast<int>(new_sink_stream.Length()))
return WRITE_ERROR;
« courgette/third_party/bsdiff/bsdiff.h ('K') | « courgette/third_party/bsdiff/bsdiff.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698