diff options
Diffstat (limited to 'applypatch')
-rw-r--r-- | applypatch/Android.mk | 13 | ||||
-rw-r--r-- | applypatch/applypatch.cpp | 14 | ||||
-rw-r--r-- | applypatch/imgdiff.cpp | 29 |
3 files changed, 24 insertions, 32 deletions
diff --git a/applypatch/Android.mk b/applypatch/Android.mk index cc17a13ae..93a272997 100644 --- a/applypatch/Android.mk +++ b/applypatch/Android.mk @@ -39,19 +39,6 @@ include $(BUILD_EXECUTABLE) include $(CLEAR_VARS) LOCAL_CLANG := true -LOCAL_SRC_FILES := main.cpp -LOCAL_MODULE := applypatch_static -LOCAL_FORCE_STATIC_EXECUTABLE := true -LOCAL_MODULE_TAGS := eng -LOCAL_C_INCLUDES += bootable/recovery -LOCAL_STATIC_LIBRARIES += libapplypatch libbase libmtdutils libmincrypt libbz -LOCAL_STATIC_LIBRARIES += libz libcutils libc - -include $(BUILD_EXECUTABLE) - -include $(CLEAR_VARS) - -LOCAL_CLANG := true LOCAL_SRC_FILES := imgdiff.cpp utils.cpp bsdiff.cpp LOCAL_MODULE := imgdiff LOCAL_FORCE_STATIC_EXECUTABLE := true diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 751d3e392..f9425af93 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -25,12 +25,13 @@ #include <sys/types.h> #include <unistd.h> -#include <base/strings.h> +#include <android-base/strings.h> #include "mincrypt/sha.h" #include "applypatch.h" #include "mtdutils/mtdutils.h" #include "edify/expr.h" +#include "print_sha1.h" static int LoadPartitionContents(const char* filename, FileContents* file); static ssize_t FileSink(const unsigned char* data, ssize_t len, void* token); @@ -43,7 +44,6 @@ static int GenerateTarget(FileContents* source_file, const uint8_t target_sha1[SHA_DIGEST_SIZE], size_t target_size, const Value* bonus_data); -static std::string short_sha1(const uint8_t sha1[SHA_DIGEST_SIZE]); static bool mtd_partitions_scanned = false; @@ -630,16 +630,6 @@ int CacheSizeCheck(size_t bytes) { } } -static std::string short_sha1(const uint8_t sha1[SHA_DIGEST_SIZE]) { - const char* hex = "0123456789abcdef"; - std::string result = ""; - for (size_t i = 0; i < 4; ++i) { - result.push_back(hex[(sha1[i]>>4) & 0xf]); - result.push_back(hex[sha1[i] & 0xf]); - } - return result; -} - // This function applies binary patches to files in a way that is safe // (the original file is not touched until we have the desired // replacement for it) and idempotent (it's okay to run this program diff --git a/applypatch/imgdiff.cpp b/applypatch/imgdiff.cpp index 4d83ffb2e..f22502e38 100644 --- a/applypatch/imgdiff.cpp +++ b/applypatch/imgdiff.cpp @@ -407,6 +407,7 @@ unsigned char* ReadImage(const char* filename, while (pos < sz) { unsigned char* p = img+pos; + bool processed_deflate = false; if (sz - pos >= 4 && p[0] == 0x1f && p[1] == 0x8b && p[2] == 0x08 && // deflate compression @@ -460,18 +461,24 @@ unsigned char* ReadImage(const char* filename, strm.next_out = curr->data + curr->len; ret = inflate(&strm, Z_NO_FLUSH); if (ret < 0) { - printf("Error: inflate failed [%s] at file offset [%zu]\n" - "imgdiff only supports gzip kernel compression," - " did you try CONFIG_KERNEL_LZO?\n", - strm.msg, chunk_offset); - free(img); - return NULL; + if (!processed_deflate) { + // This is the first chunk, assume that it's just a spurious + // gzip header instead of a real one. + break; + } + printf("Error: inflate failed [%s] at file offset [%zu]\n" + "imgdiff only supports gzip kernel compression," + " did you try CONFIG_KERNEL_LZO?\n", + strm.msg, chunk_offset); + free(img); + return NULL; } curr->len = allocated - strm.avail_out; if (strm.avail_out == 0) { allocated *= 2; curr->data = reinterpret_cast<unsigned char*>(realloc(curr->data, allocated)); } + processed_deflate = true; } while (ret != Z_STREAM_END); curr->deflate_len = sz - strm.avail_in - pos; @@ -628,7 +635,15 @@ unsigned char* MakePatch(ImageChunk* src, ImageChunk* tgt, size_t* size) { } char ptemp[] = "/tmp/imgdiff-patch-XXXXXX"; - mkstemp(ptemp); + int fd = mkstemp(ptemp); + + if (fd == -1) { + printf("MakePatch failed to create a temporary file: %s\n", + strerror(errno)); + return NULL; + } + close(fd); // temporary file is created and we don't need its file + // descriptor int r = bsdiff(src->data, src->len, &(src->I), tgt->data, tgt->len, ptemp); if (r != 0) { |