summaryrefslogtreecommitdiffstats
path: root/applypatch/imgdiff.cpp (unfollow)
Commit message (Collapse)AuthorFilesLines
2020-09-18Check for overflow before allocating memory fore decompression.Kelvin Zhang1-4/+30
On 32bit devices, an ZipEntry64 may have size > 2^32, we should check for such cases before attempting to allocate memory. Test: mm -j Change-Id: I0f916ef4b2a692f167719a74bd6ff2e887c6c2ce
2020-09-16Switch to zip64 in recoveryKelvin Zhang1-3/+3
There's already library support for zip64 in libziparchive. We just need to start using the new APIs. Bug: 167951876 Test: Sideload a large ota package in recovery Change-Id: I652741965f28de079d873c6822317ee9fa855201
2020-07-23Update language to comply with Android’s inclusive language guidanceTianjie1-7/+8
https: //source.android.com/setup/contribute/respectful-code Bug: 161896447 Test: Unit tests pass Change-Id: I0f3f0333dbccc94241a096ca5d3d9bc28c281492
2020-03-08Address the warnings in recovery codeTianjie Xu1-3/+3
The following warnngs generate when compile with WITH_TIDY=1 .../bootable/recovery/applypatch/imgdiff.cpp:968:7: warning: 'src_ranges' used after it was moved [bugprone-use-after-move] src_ranges.Clear(); ^ .../bootable/recovery/applypatch/imgdiff.cpp:966:27: note: move occurred here split_src_ranges->push_back(std::move(src_ranges)); The logic itself seems correct since the class is meant to be cleared after move. I feel the std::move in 966 is actually useful to call the move constructor in RangeSet. So I just modify L968 to suppress the warning. Less important ones: bootable/recovery/applypatch/applypatch_modes.cpp:79:34: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] bootable/recovery/applypatch/imgdiff.cpp:1038:30: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] bootable/recovery/applypatch/imgdiff.cpp:1054:48: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] bootable/recovery/updater/include/private/commands.h:310:16: warning: std::move of the variable 'patch' of the trivially-copyable type 'PatchInfo' has no effect; remove std::move() [performance-move-const-arg] bootable/recovery/updater/install.cpp:663:43: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] Bug: 150955971 Test: build Change-Id: Ieb75f0229c47d470d4f5ac93fab39c5698d3f914
2019-05-23Move off the Next ZipString overload.Elliott Hughes1-3/+2
Bug: http://b/129068177 Test: treehugger Change-Id: I3c8f70b0d8cc5dc6b3b4439dbe0b9a5bd85003c4
2019-05-09Track libziparchive API change.Elliott Hughes1-1/+1
Bug: http://b/129068177 Test: treehugger Change-Id: I618bbcf38914dd81e042e0cfd1976ff26274dc30
2018-05-24Convert deflate image chunks to raw if the raw data is smallerTianjie Xu1-2/+2
The imgpatch will fail on empty deflates because the bspatch won't call the sink function if the target length is zero. Instead of compressing an empty string, it's cleaner to not generate such empty deflate chunks in the patch. Therefore, we can just convert the chunk type to raw if the target length is smaller than the patch data. Also adjust some unit tests and add the testdata gzipped_source & gzipped_target. These two files are ~1K each and are generated by gzipping two slightly different regular files. Bug: 79265132 Test: unit tests pass, imgpatch applys successfully on the given src/tgt Change-Id: I6bfff3251918137f6762a6f9e9551642371a1124
2018-02-23Remove the assumption of target chunk size in imgdiffTianjie Xu1-18/+27
In the split mode of imgdiff, we used to assume that the size of a split target chunk is always greater than the blocksize i.e. 4096. This may lead to the following assertion failure: I0221 04:57:33.451323 818464 common.py:205 imgdiff F 02-21 04:57:33 821203 821203 imgdiff.cpp:999] Check failed: tgt_size >= BLOCK_SIZE (tgt_size=476, BLOCK_SIZE=4096) This CL removes the assumption and handles the edge cases. Test: generate and verify the incremental update for TFs in the bug; unit test passes Bug: 73757557 Bug: 73711365 Change-Id: Iadbb4ee658995f5856cd488f3793980881a59620
2017-11-16Switch imgdiff to libbase loggingTianjie Xu1-92/+107
Also add a verbose option. And we won't print messages of 'info' severity unless '-v' is present. Test: run imgdiff and check the logs. Change-Id: I1b90874baea8e72e2a2323a0b63bc5d35e653e6b
2017-10-24Use SuffixArrayIndexInterface opaque type instead of the underlying data pointer.Alex Deymo1-5/+7
bsdiff interface is changing such that it hides the suffix array pointer from the public interface. This allows to use a different suffix array data size depending on the input size, running much faster in the normal case. Bug: 34220646 Test: `make checkbuild`; Ran an incremental update generation on a non-A/B device. Change-Id: I78e766da56cf28bc7774b8c8e58527bc11d919fb
2017-10-16otautil: Move RangeSet implementation into rangeset.cpp.Tao Bao1-0/+2
Since it has grown much larger, users of the header shouldn't compile and carry their full copies. Also add missing header includes in imgdiff.cpp and imgdiff_test.cpp. Test: mmma bootable/recovery Test: recovery_unit_test; recovery_component_test; recovery_host_test Change-Id: I88ca54171765e5606ab0d61580fbc1ada578fd7d
2017-10-11Move rangeset.h and print_sha1.h into otautil.Tao Bao1-1/+1
Also drop the "bootable/recovery" path in LOCAL_C_INCLUDES from applypatch modules. Test: lunch aosp_{angler,bullhead,fugu,dragon,sailfish}-userdebug; mmma bootable/recovery Change-Id: Idd602a796894f971ee4f8fa3eafe36c42d9de986
2017-09-21Output split information for imgdiff when handling large apksTianjie Xu1-60/+129
Add a mandatory option in imgdiff to write the split info (i.e. patch_size, tgt_size, src_ranges) to file when handling large apks. Therefore, the caller of imgdiff can create split transfers based on the info. Bug: 63542719 Test: unit tests pass Change-Id: I853d55d1f999fd576474faa81077f7307f4d856d
2017-09-06Improve imgdiff for large zip filesTianjie Xu1-18/+423
Due to the cache size limit for OTA generation, we used to split large zip files linearly into pieces and do bsdiff on them. As a result, i) we lose the advantage of imgdiff; ii) if there's an accidental order change of some huge files inside the zip, we'll create an insanely large patch. This patch splits the src&tgt more smartly based on the zip entry_name. If the entry_name is empty or no matching source is found for a target chunk, we'll skip adding its source and later do a bsdiff against the whole split source image (this rarely happens in our use cases except for the metadata inside a ziparchive). After the split, the target pieces are continuous and block aligned, while the sources pieces are mutually exclusive. (Some of the source blocks may not be used if there's no matching entry_name in the target.) Then we will generate patches accordingly between each split image pairs. Afterwards, if we apply imgpatch to each pair of split source/target images and add up the patched result, we can get back the original target image. For example: Input: [src_image, tgt_image] Split: [src-0,tgt-0; src-1,tgt-1, src-2,tgt-2] Diff: [ patch-0; patch-1; patch-2] Patch: [(src-0,patch-0)=tgt-0; (src-1,patch-1)=tgt-1; (src-2,patch-2)=tgt-2;] Append: [tgt-0 + tgt-1 + tgt-2 = tgt_image] Peformance: For the small package in b/34220646, we decrease the patch size of chrome.apk dramatically from 30M to 400K due to the order change of two big .so files. On two versions of angler, I also observe decent patch size decrease. For chrome.apk, we reduced the size from 5.9M to 3.2M; and for vevlet.apk from 8.0M to 6.5M. Bug: 34220646 Test: recovery component test && apply imgdiff & imgpatch on two chrome.apk Change-Id: I145d802984fa805efbbac9d01a2e64d82ef9728b
2017-08-19Move Image/ImageChunk/PatchChunk declaration into header filesTianjie Xu1-270/+65
1. Move the declaration of the Image classes to the header file to make testing easier. 2. Also move rangeset.h to bootable/recovery to allow access in imgdiff. Test: recovery component test Change-Id: I68a863e60a3f2e7ae46ee48f48eb15391f5f4330
2017-08-13Add a new PatchChunk class in imgdiffTianjie Xu1-236/+292
This way we can keep the input images const when calling genetatepatches(). Test: recovery component test; diff and patch on chrome.apk; generate recovery-from-boot.p for angler. Change-Id: I65b5689b88f6719c6ede46bb82def0c4caeb8a61
2017-08-02Refactor the imgdiffTianjie Xu1-392/+567
This helps us to add a new mode to handle large APKs in the follow up CL. Changes include: 1. Create a new interface class 'Image' 1. Create subclasses 'ZipModeImage' and 'ImageModeImage' and move the related functions there. Bug: 63542719 Test: recovery_component_test passes Change-Id: I7729b0ba39b19a9c84811636a60dd0a0b1acc2f0
2017-07-07Fix a rare failure for imgdiff when random data equals gzip headerTianjie Xu1-11/+14
In a rare case, a random chunk will pass both the gzip header check and the inflation process; but fail the uncompressed length check in the footer. This leads to a imgdiff failure. So, we should treat this chunk as 'normal' instead of 'inflated' while generating the patch. Bug: 63334984 Test: imgdiff generates patch successfully on previous failing images. Change-Id: Ice84f22d3653bce9756bda91e70528c0d2f264a0
2017-03-16More cleanup to imgdiff & imgpatchTianjie Xu1-79/+106
Also remove the utils in applypatch and replace them with the corresponding libbase functions. Test: recovery tests pass. Change-Id: I77254c141bd3e7d3d6894c23b60e866009516f81
2017-03-07Refractor the code for imgdiffTianjie Xu1-618/+593
Put ImageChunk and some helper functions into a class. Also switch to using std::vector instead of malloc. Bug: 18606652 Test: imgdiff_test passed on host. Also generate a complete incremental OTA package. The file content is the same and time consumption is similar. Change-Id: Id603ada4e130ef521218400761a119001a86ca79
2017-01-19imgdiff: cache bsdiff suffix array in zip mode.Sen Jiang1-13/+17
In zip mode, if a chunk is not deflate or its filename can't be found in source chunks, the entire source file is used as old data for bsdiff, To avoid repeatedly construct the suffix array used by bsdiff, we cache the suffix array of the entire source file. Bug: 34281147 Test: =time -v imgdiff -z Chrome-ORF74B.apk Chrome-ORF76B.apk Chrome.imgdiff Change-Id: Ifd957ccecf7226fcb44dbf28c58969a06ef74f4b
2016-12-28imgdiff: Fix an edge case that leads to infinite loop.Tao Bao1-15/+10
When the input image ends with the magic value sequence of 0x1f, 0x8b, 0x0b (optionally with 0x00), the image parsing code will be stuck in an infinite loop. Test: recovery_component_test passes. Change-Id: Ie3629dfdc41360387b19cc3e0359c95ae4fb998e
2016-12-20Add tests for imgdiff.Tao Bao1-30/+24
Factor out libimgdiff static library for testing purpose. This CL adds the imgdiff tests on host and on target both (similar to libimgpatch). In practice, we only need imgdiff binary on host, and libimgpatch on target. But they should build and pass tests on both platforms. Test: recovery_host_test passes; recovery_component_test passes. Change-Id: I0eafb7faf727cdf70066310e845af6ee245d4f60
2016-12-07bootable/recovery: cleanup compiler warnings (potential leak of memory)Rahul Chaudhry1-0/+1
bootable/recovery/applypatch/imgdiff.cpp:195:5: warning: Potential leak of memory pointed to by 'img' [clang-analyzer-unix.Malloc] Bug: 26936282 Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mm Change-Id: Ie79c780233ddfebf85686a24df3bf2561f831580
2016-11-30bootable/recovery: cleanup compiler warnings (unused value)Rahul Chaudhry1-0/+16
bootable/recovery/applypatch/imgdiff.cpp:322:11: warning: Value stored to 'ret' during its initialization is never read [clang-analyzer-deadcode.DeadStores] bootable/recovery/applypatch/imgdiff.cpp:447:11: warning: Value stored to 'ret' during its initialization is never read [clang-analyzer-deadcode.DeadStores] bootable/recovery/applypatch/imgdiff.cpp:553:3: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores] Bug: 26936282 Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mm Change-Id: I3f865e3e9b9d19e5ea5e8dfd2fe2c644254ffbb5
2016-11-16Use static_cast to cast pointers returned by malloc/calloc/realloc/mmap.Rahul Chaudhry1-16/+16
static_cast is preferable to reinterpret_cast when casting from void* pointers returned by malloc/calloc/realloc/mmap calls. Discovered while looking at compiler warnings (b/26936282). Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mma Change-Id: Iaffd537784aa857108f6981fdfd82d0496eb5592 Merged-In: I151642d5a60c94f312d0611576ad0143c249ba3d
2016-11-16bootable/recovery: cleanup compiler warnings (potential leak of memory)Rahul Chaudhry1-0/+4
bootable/recovery/applypatch/imgdiff.cpp:1065:3: warning: Potential leak of memory pointed to by 'patch_data' bootable/recovery/applypatch/imgdiff.cpp:1065:3: warning: Potential leak of memory pointed to by 'patch_size' bootable/recovery/applypatch/imgdiff.cpp:226:7: warning: Potential leak of memory pointed to by 'temp_entries' Bug: 26936282 Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mm Change-Id: I3cac945d7677d367934d5619ef7419daf6f48d6f
2016-11-09Use static_cast to cast pointers returned by malloc/calloc/realloc/mmap.Rahul Chaudhry1-16/+16
static_cast is preferable to reinterpret_cast when casting from void* pointers returned by malloc/calloc/realloc/mmap calls. Discovered while looking at compiler warnings (b/26936282). Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mma Change-Id: I151642d5a60c94f312d0611576ad0143c249ba3d
2016-06-01Revert "Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector."Tao Bao1-38/+40
This reverts commit 51dc9444bcf8d8900a521795e873d07f6cd445ef. A new/free mismatch may lead to memory corruptions. Change-Id: I3e10ae9e514abe59c351d2f27bedd3f8fcd1d137
2016-06-01Revert "Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector."Tao Bao1-38/+40
This reverts commit 50a6f8c8335be920833d06e5dabd37de279c98a9. A mix of new and free leads to memory corruptions.
2016-06-01Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector.Adam Buchbinder1-40/+38
This fixes the following cppcheck reports: [imgdiff.cpp:197]: (error) Memory leak: img [imgdiff.cpp:386]: (error) Memory leak: img [imgdiff.cpp:656]: (error) Memory leak: data [imgdiff.cpp:664]: (error) Memory leak: data [imgdiff.cpp:668]: (error) Memory leak: data [imgdiff.cpp:668]: (error) Resource leak: f [imgdiff.cpp:820]: (error) Memory leak: bonus_data [imgdiff.cpp:824]: (error) Memory leak: bonus_data [imgdiff.cpp:824]: (error) Resource leak: f [imgdiff.cpp:847]: (error) Memory leak: bonus_data [imgdiff.cpp:851]: (error) Memory leak: bonus_data [imgdiff.cpp:856]: (error) Memory leak: bonus_data [imgdiff.cpp:860]: (error) Memory leak: bonus_data [imgdiff.cpp:227]: (error) Memory leak: temp_entries Change-Id: I06f878d0b677a25328e0deb84f65f3b7212e24b1 (cherry picked from commit 51dc9444bcf8d8900a521795e873d07f6cd445ef)
2016-05-26Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector.Adam Buchbinder1-40/+38
This fixes the following cppcheck reports: [imgdiff.cpp:197]: (error) Memory leak: img [imgdiff.cpp:386]: (error) Memory leak: img [imgdiff.cpp:656]: (error) Memory leak: data [imgdiff.cpp:664]: (error) Memory leak: data [imgdiff.cpp:668]: (error) Memory leak: data [imgdiff.cpp:668]: (error) Resource leak: f [imgdiff.cpp:820]: (error) Memory leak: bonus_data [imgdiff.cpp:824]: (error) Memory leak: bonus_data [imgdiff.cpp:824]: (error) Resource leak: f [imgdiff.cpp:847]: (error) Memory leak: bonus_data [imgdiff.cpp:851]: (error) Memory leak: bonus_data [imgdiff.cpp:856]: (error) Memory leak: bonus_data [imgdiff.cpp:860]: (error) Memory leak: bonus_data [imgdiff.cpp:227]: (error) Memory leak: temp_entries Change-Id: I06f878d0b677a25328e0deb84f65f3b7212e24b1
2016-05-04applypatch: Use bsdiff from external/bsdiff.Sen Jiang1-14/+3
external/bsdiff uses divsufsort which is much faster, and also include some bug fixes. Bug: 26982501 Test: ./imgdiff_test.sh Change-Id: I089a301c291ee55d79938c7a3ca6d509895440d1
2016-02-12imgdiff: don't fail if gzip is corrupted.Sen Jiang1-12/+10
Treat it as a normal chunk if inflate() fails. Test: run imgdiff on corrupted gzip and apply the patch Bug: 27153028 Change-Id: Idcbb3c1360ec0774e6c7861b21d99af8ee10604a
2016-02-10applypatch: Add a Makefile to build imgdiff in Chrome OS.Sen Jiang1-2/+0
Also fixed some warnings and added check for target_len. Test: mma; emerge-peppy imgdiff; emerge-nyan imgdiff; sudo emerge imgdiff Bug: 26866274 Change-Id: Ifbcd3afd6701c769ccf626e33ed94461706f7ee6
2015-12-23imgdiff: skip spurious gzip headers in image filesDavid Riley1-6/+13
dragon kernel is compressed via lz4 for boot speed and bootloader support reasons and recent prebuilts happen to include the gzip header sequence which is causing imgdiff to fail. Detect a spurious gzip header and treat the section as a normal section. Bug: 26133184 Change-Id: I369d7d576fd7d2c579c0780fc5c669a5b6ea0d3d (cherry picked from commit 0f2f6a746af517afca9e5e089a4a17be0a9766d6) Signed-off-by: David Riley <davidriley@google.com>
2015-11-16DO NOT MERGE recovery: Switch applypatch/ and updater/ to cpp.Tao Bao1-38/+46
Mostly trivial changes to make cpp compiler happy. Change-Id: I69bd1d96fcccf506007f6144faf37e11cfba1270 (cherry picked from commit ba9a42aa7e10686de186636fe9fecbf8c4cc7c19)
2015-07-14recovery: Switch applypatch/ and updater/ to cpp.Tao Bao1-1060/+0
Mostly trivial changes to make cpp compiler happy. Change-Id: I1b0481465c67c3bbca35a839d0764190d84ff34e (cherry picked from commit ba9a42aa7e10686de186636fe9fecbf8c4cc7c19)
2015-07-14recovery: Switch applypatch/ and updater/ to cpp.Tao Bao1-1060/+0
Mostly trivial changes to make cpp compiler happy. Change-Id: I69bd1d96fcccf506007f6144faf37e11cfba1270
2015-04-15imgdiff: Avoid infinite loop if inflate failsJohan Redestig1-0/+9
Break out of the loop if inflate returns an error and print some details. Change-Id: Ie157cf943291b1a26f4523b17691dfcefbc881dc
2012-08-21add bonus data feature to imgdiff/imgpatch/applypatchDoug Zongker1-8/+49
The bonus data option lets you give an additional blob of uncompressed data to be used when constructing a patch for chunk #1 of an image. The same blob must be available at patch time, and can be passed to the command-line applypatch tool (this feature is not accessible from edify scripts). This will be used to reduce the size of recovery-from-boot patches by storing parts of the recovery ramdisk (the UI images) on the system partition. Change-Id: Iac1959cdf7f5e4582f8d434e83456e483b64c02c
2010-02-18relocate applypatch; add type system and new functions to edifyDoug Zongker1-0/+1010
- Move applypatch to this package (from build). - Add a rudimentary type system to edify: instead of just returning a char*, functions now return a Value*, which is a struct that can carry different types of value (currently just STRING and BLOB). Convert all functions to this new scheme. - Change the one-argument form of package_extract_file to return a Value of the new BLOB type. - Add read_file() to load a local file and return a blob, and sha1_check() to test a blob (or string) against a set of possible sha1s. read_file() uses the file-loading code from applypatch so it can read MTD partitions as well. This is the start of better integration between applypatch and the rest of edify. b/2361316 - VZW Issue PP628: Continuous reset to Droid logo: framework-res.apk update failed (CR LIBtt59130) Change-Id: Ibd038074749a4d515de1f115c498c6c589ee91e5