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

Side by Side Diff: courgette/third_party/bsdiff/bsdiff_apply.cc

Issue 2534873005: Sandbox the component updater's patcher utility process. (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright 2003, 2004 Colin Percival 1 // Copyright 2003, 2004 Colin Percival
2 // All rights reserved 2 // All rights reserved
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted providing that the following conditions 5 // modification, are permitted providing that the following conditions
6 // are met: 6 // are met:
7 // 1. Redistributions of source code must retain the above copyright 7 // 1. Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer. 8 // notice, this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright 9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the 10 // notice, this list of conditions and the following disclaimer in the
(...skipping 22 matching lines...) Expand all
33 33
34 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 34 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
35 // Use of this source code is governed by a BSD-style license that can be 35 // Use of this source code is governed by a BSD-style license that can be
36 // found in the LICENSE file. 36 // found in the LICENSE file.
37 37
38 #include "courgette/third_party/bsdiff/bsdiff.h" 38 #include "courgette/third_party/bsdiff/bsdiff.h"
39 39
40 #include <stddef.h> 40 #include <stddef.h>
41 #include <stdint.h> 41 #include <stdint.h>
42 42
43 #include "base/files/file.h"
43 #include "base/files/memory_mapped_file.h" 44 #include "base/files/memory_mapped_file.h"
44 #include "courgette/crc.h" 45 #include "courgette/crc.h"
45 #include "courgette/streams.h" 46 #include "courgette/streams.h"
46 47
47 namespace { 48 namespace {
48 49
49 using courgette::CalculateCrc; 50 using courgette::CalculateCrc;
50 using courgette::SinkStream; 51 using courgette::SinkStream;
51 using courgette::SinkStreamSet; 52 using courgette::SinkStreamSet;
52 using courgette::SourceStream; 53 using courgette::SourceStream;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 return CRC_ERROR; 186 return CRC_ERROR;
186 187
187 MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream); 188 MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream);
188 189
189 return OK; 190 return OK;
190 } 191 }
191 192
192 BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_file_path, 193 BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_file_path,
193 const base::FilePath& patch_file_path, 194 const base::FilePath& patch_file_path,
194 const base::FilePath& new_file_path) { 195 const base::FilePath& new_file_path) {
196 return ApplyBinaryPatch(
197 base::File(
198 base::FilePath(old_file_path),
199 base::File::FLAG_OPEN | base::File::FLAG_READ),
200 base::File(
201 base::FilePath(patch_file_path),
202 base::File::FLAG_OPEN | base::File::FLAG_READ),
203 base::File(
204 base::FilePath(new_file_path),
205 base::File::FLAG_CREATE_ALWAYS |
206 base::File::FLAG_WRITE |
207 base::File::FLAG_EXCLUSIVE_WRITE));
208 }
209
210 BSDiffStatus ApplyBinaryPatch(base::File old_file,
211 base::File patch_file,
212 base::File new_file) {
195 // Set up the old stream. 213 // Set up the old stream.
196 base::MemoryMappedFile old_file; 214 base::MemoryMappedFile old_file_mem;
197 if (!old_file.Initialize(old_file_path)) { 215 if (!old_file_mem.Initialize(std::move(old_file))) {
198 return READ_ERROR; 216 return READ_ERROR;
199 } 217 }
200 SourceStream old_file_stream; 218 SourceStream old_file_stream;
201 old_file_stream.Init(old_file.data(), old_file.length()); 219 old_file_stream.Init(old_file_mem.data(), old_file_mem.length());
202 220
203 // Set up the patch stream. 221 // Set up the patch stream.
204 base::MemoryMappedFile patch_file; 222 base::MemoryMappedFile patch_file_mem;
205 if (!patch_file.Initialize(patch_file_path)) { 223 if (!patch_file_mem.Initialize(std::move(patch_file))) {
206 return READ_ERROR; 224 return READ_ERROR;
207 } 225 }
208 SourceStream patch_file_stream; 226 SourceStream patch_file_stream;
209 patch_file_stream.Init(patch_file.data(), patch_file.length()); 227 patch_file_stream.Init(patch_file_mem.data(), patch_file_mem.length());
210 228
211 // Set up the new stream and apply the patch. 229 // Set up the new stream and apply the patch.
212 SinkStream new_sink_stream; 230 SinkStream new_sink_stream;
213 BSDiffStatus status = 231 BSDiffStatus status =
214 ApplyBinaryPatch(&old_file_stream, &patch_file_stream, &new_sink_stream); 232 ApplyBinaryPatch(&old_file_stream, &patch_file_stream, &new_sink_stream);
215 if (status != OK) { 233 if (status != OK) {
216 return status; 234 return status;
217 } 235 }
218 236
219 // Write the stream to disk. 237 // 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.
220 int written = base::WriteFile( 238 int written = new_file.Write(
221 new_file_path, reinterpret_cast<const char*>(new_sink_stream.Buffer()), 239 0,
240 reinterpret_cast<const char*>(new_sink_stream.Buffer()),
222 static_cast<int>(new_sink_stream.Length())); 241 static_cast<int>(new_sink_stream.Length()));
223 if (written != static_cast<int>(new_sink_stream.Length())) 242 if (written != static_cast<int>(new_sink_stream.Length()))
224 return WRITE_ERROR; 243 return WRITE_ERROR;
225 return OK; 244 return OK;
226 } 245 }
227 246
228 } // namespace bsdiff 247 } // namespace bsdiff
OLDNEW
« 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