From cc61cf6a9f74400956886c7f91efef581f4184e2 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Wed, 23 May 2018 22:23:31 -0700 Subject: 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 --- applypatch/imgpatch.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'applypatch/imgpatch.cpp') diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp index c4c2707fb..2f8f4851d 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(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); -- cgit v1.2.3