diff options
author | David Riley <davidriley@google.com> | 2015-12-10 10:18:25 -0800 |
---|---|---|
committer | Dan Pasanen <invisiblek@cyanogenmod.org> | 2015-12-28 07:23:41 -0600 |
commit | 46e4090df4dd016d2ebeeb3b1b1f1b6d0b13c614 (patch) | |
tree | 60849d9fd6105309d52377f1353798ffabcf2930 | |
parent | 3010668acc5282de04be11541dab88eaa56683e6 (diff) | |
download | bootable_recovery-46e4090df4dd016d2ebeeb3b1b1f1b6d0b13c614.zip bootable_recovery-46e4090df4dd016d2ebeeb3b1b1f1b6d0b13c614.tar.gz bootable_recovery-46e4090df4dd016d2ebeeb3b1b1f1b6d0b13c614.tar.bz2 |
imgdiff: skip spurious gzip headers in image files
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>
-rw-r--r-- | applypatch/imgdiff.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/applypatch/imgdiff.c b/applypatch/imgdiff.c index d20fb39..3a2eb91 100644 --- a/applypatch/imgdiff.c +++ b/applypatch/imgdiff.c @@ -122,6 +122,7 @@ */ #include <errno.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -405,6 +406,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 @@ -457,18 +459,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 = realloc(curr->data, allocated); } + processed_deflate = true; } while (ret != Z_STREAM_END); curr->deflate_len = st.st_size - strm.avail_in - pos; |