aboutsummaryrefslogtreecommitdiffstats
path: root/applypatch
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2018-05-23 22:23:31 -0700
committerTianjie Xu <xunchang@google.com>2018-05-24 10:49:54 -0700
commitcc61cf6a9f74400956886c7f91efef581f4184e2 (patch)
tree3647f091fdaf8f61f3b97de44fdecee6aff1f782 /applypatch
parent5b3d6cf58b5d05ba01fe3941c7f70c37babd08d8 (diff)
downloadandroid_bootable_recovery-cc61cf6a9f74400956886c7f91efef581f4184e2.tar.gz
android_bootable_recovery-cc61cf6a9f74400956886c7f91efef581f4184e2.tar.bz2
android_bootable_recovery-cc61cf6a9f74400956886c7f91efef581f4184e2.zip
Convert deflate image chunks to raw if the raw data is smaller
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
Diffstat (limited to 'applypatch')
-rw-r--r--applypatch/imgdiff.cpp4
-rw-r--r--applypatch/imgpatch.cpp1
-rw-r--r--applypatch/include/applypatch/imgdiff_image.h3
3 files changed, 5 insertions, 3 deletions
diff --git a/applypatch/imgdiff.cpp b/applypatch/imgdiff.cpp
index 674cc2b1..415d95f1 100644
--- a/applypatch/imgdiff.cpp
+++ b/applypatch/imgdiff.cpp
@@ -462,12 +462,12 @@ PatchChunk::PatchChunk(const ImageChunk& tgt)
target_len_(tgt.GetRawDataLength()),
target_uncompressed_len_(tgt.DataLengthForPatch()),
target_compress_level_(tgt.GetCompressLevel()),
- data_(tgt.DataForPatch(), tgt.DataForPatch() + tgt.DataLengthForPatch()) {}
+ data_(tgt.GetRawData(), tgt.GetRawData() + tgt.GetRawDataLength()) {}
// Return true if raw data is smaller than the patch size.
bool PatchChunk::RawDataIsSmaller(const ImageChunk& tgt, size_t patch_size) {
size_t target_len = tgt.GetRawDataLength();
- return (tgt.GetType() == CHUNK_NORMAL && (target_len <= 160 || target_len < patch_size));
+ return target_len < patch_size || (tgt.GetType() == CHUNK_NORMAL && target_len <= 160);
}
void PatchChunk::UpdateSourceOffset(const SortedRangeSet& src_range) {
diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp
index c4c2707f..2f8f4851 100644
--- a/applypatch/imgpatch.cpp
+++ b/applypatch/imgpatch.cpp
@@ -54,6 +54,7 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_
const Value& patch, size_t patch_offset,
const char* deflate_header, SinkFn sink) {
size_t expected_target_length = static_cast<size_t>(Read8(deflate_header + 32));
+ CHECK_GT(expected_target_length, 0);
int level = Read4(deflate_header + 40);
int method = Read4(deflate_header + 44);
int window_bits = Read4(deflate_header + 48);
diff --git a/applypatch/include/applypatch/imgdiff_image.h b/applypatch/include/applypatch/imgdiff_image.h
index 08480723..67160516 100644
--- a/applypatch/include/applypatch/imgdiff_image.h
+++ b/applypatch/include/applypatch/imgdiff_image.h
@@ -44,6 +44,8 @@ class ImageChunk {
int GetType() const {
return type_;
}
+
+ const uint8_t* GetRawData() const;
size_t GetRawDataLength() const {
return raw_data_len_;
}
@@ -99,7 +101,6 @@ class ImageChunk {
bsdiff::SuffixArrayIndexInterface** bsdiff_cache);
private:
- const uint8_t* GetRawData() const;
bool TryReconstruction(int level);
int type_; // CHUNK_NORMAL, CHUNK_DEFLATE, CHUNK_RAW