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

Side by Side Diff: build/android/rezip/rezip.cc

Issue 364193003: When building APK for direct loading, check for multiple libraries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Check for multiple libraries, fix comment. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // rezip is a tool which is used to modify zip files. It reads in a 5 // rezip is a tool which is used to modify zip files. It reads in a
6 // zip file and outputs a new zip file after applying various 6 // zip file and outputs a new zip file after applying various
7 // transforms. The tool is used in the Android Chromium build process 7 // transforms. The tool is used in the Android Chromium build process
8 // to modify an APK file (which are zip files). The main application 8 // to modify an APK file (which are zip files). The main application
9 // of this is to modify the APK so that the shared library is no 9 // of this is to modify the APK so that the shared library is no
10 // longer compressed. Ironically, this saves both transmission and 10 // longer compressed. Ironically, this saves both transmission and
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return extra_size; 255 return extra_size;
256 } 256 }
257 257
258 assert(extra_size < kMaxExtraFieldInZip - padding); 258 assert(extra_size < kMaxExtraFieldInZip - padding);
259 memset(extra_buffer + extra_size, 0, padding); 259 memset(extra_buffer + extra_size, 0, padding);
260 return extra_size + padding; 260 return extra_size + padding;
261 } 261 }
262 262
263 // As only the read side API provides offsets, we check that we added the 263 // As only the read side API provides offsets, we check that we added the
264 // correct amount of padding by reading the zip file we just generated. 264 // correct amount of padding by reading the zip file we just generated.
265 static bool CheckPageAlign(const char* out_zip_filename) { 265 // Also enforce that only one library is in the APK.
266 static bool CheckPageAlignAndOnlyOneLibrary(const char* out_zip_filename) {
266 ScopedUnzip scoped_unzip(out_zip_filename); 267 ScopedUnzip scoped_unzip(out_zip_filename);
267 unzFile in_file = scoped_unzip.OpenOrDie(); 268 unzFile in_file = scoped_unzip.OpenOrDie();
268 269
269 int err = 0; 270 int err = 0;
271 int count = 0;
270 bool checked = false; 272 bool checked = false;
271 while (true) { 273 while (true) {
272 char in_filename[kMaxFilenameInZip + 1]; 274 char in_filename[kMaxFilenameInZip + 1];
273 // Get info and extra field for current file. 275 // Get info and extra field for current file.
274 unz_file_info in_info; 276 unz_file_info in_info;
275 err = unzGetCurrentFileInfo(in_file, 277 err = unzGetCurrentFileInfo(in_file,
276 &in_info, 278 &in_info,
277 in_filename, 279 in_filename,
278 sizeof(in_filename) - 1, 280 sizeof(in_filename) - 1,
279 NULL, 281 NULL,
280 0, 282 0,
281 NULL, 283 NULL,
282 0); 284 0);
283 if (err != UNZ_OK) { 285 if (err != UNZ_OK) {
284 LOG(ERROR) << "failed to get filename" << out_zip_filename; 286 LOG(ERROR) << "failed to get filename" << out_zip_filename;
285 return false; 287 return false;
286 } 288 }
287 assert(in_info.size_filename <= kMaxFilenameInZip); 289 assert(in_info.size_filename <= kMaxFilenameInZip);
288 in_filename[in_info.size_filename] = '\0'; 290 in_filename[in_info.size_filename] = '\0';
289 291
290 if (IsCrazyLibraryFilename(in_filename)) { 292 if (IsCrazyLibraryFilename(in_filename)) {
293 count++;
294 if (count > 1) {
295 LOG(ERROR)
296 << "Found more than one library in " << out_zip_filename << "\n"
297 << "Multiple libraries are not supported for APKs that use "
298 << "'load_library_from_zip_file'.\n"
299 << "See crbug/388223.\n"
300 << "Note, check that your build is clean.\n"
301 << "An unclean build can incorrectly incorporate old "
302 << "libraries in the APK.";
303 return false;
304 }
291 err = unzOpenCurrentFile(in_file); 305 err = unzOpenCurrentFile(in_file);
292 if (err != UNZ_OK) { 306 if (err != UNZ_OK) {
293 LOG(ERROR) << "failed to open subfile" << out_zip_filename << " " 307 LOG(ERROR) << "failed to open subfile" << out_zip_filename << " "
294 << in_filename; 308 << in_filename;
295 return false; 309 return false;
296 } 310 }
297 311
298 const ZPOS64_T pos = unzGetCurrentFileZStreamPos64(in_file); 312 const ZPOS64_T pos = unzGetCurrentFileZStreamPos64(in_file);
299 const int alignment = pos % kPageSizeOnDevice; 313 const int alignment = pos % kPageSizeOnDevice;
300 checked = (alignment == 0); 314 checked = (alignment == 0);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 exit(1); 520 exit(1);
507 } 521 }
508 522
509 if (!Rezip(in_zip_filename, 523 if (!Rezip(in_zip_filename,
510 out_zip_filename, 524 out_zip_filename,
511 align_fun, 525 align_fun,
512 rename_fun, 526 rename_fun,
513 inflate_predicate_fun)) { 527 inflate_predicate_fun)) {
514 exit(1); 528 exit(1);
515 } 529 }
516 if (check_page_align && !CheckPageAlign(out_zip_filename)) { 530 if (check_page_align && !CheckPageAlignAndOnlyOneLibrary(out_zip_filename)) {
517 exit(1); 531 exit(1);
518 } 532 }
519 return 0; 533 return 0;
520 } 534 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698