diff options
author | Doug Zongker <dougz@google.com> | 2012-08-21 00:50:19 +0200 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2012-08-21 00:50:19 +0200 |
commit | 13a29ea9688fd6169d69f506d5028a49038c5434 (patch) | |
tree | 5f2a722ebb6f9c7d58da206c04e077a7685c646c /applypatch/imgpatch.c | |
parent | am 55850258: am 3733d218: Merge changes I664f8dc7,I4154db06,I5e1df90f (diff) | |
parent | add bonus data feature to imgdiff/imgpatch/applypatch (diff) | |
download | android_bootable_recovery-13a29ea9688fd6169d69f506d5028a49038c5434.tar android_bootable_recovery-13a29ea9688fd6169d69f506d5028a49038c5434.tar.gz android_bootable_recovery-13a29ea9688fd6169d69f506d5028a49038c5434.tar.bz2 android_bootable_recovery-13a29ea9688fd6169d69f506d5028a49038c5434.tar.lz android_bootable_recovery-13a29ea9688fd6169d69f506d5028a49038c5434.tar.xz android_bootable_recovery-13a29ea9688fd6169d69f506d5028a49038c5434.tar.zst android_bootable_recovery-13a29ea9688fd6169d69f506d5028a49038c5434.zip |
Diffstat (limited to 'applypatch/imgpatch.c')
-rw-r--r-- | applypatch/imgpatch.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/applypatch/imgpatch.c b/applypatch/imgpatch.c index e3ee80ac0..3a1df3872 100644 --- a/applypatch/imgpatch.c +++ b/applypatch/imgpatch.c @@ -37,7 +37,8 @@ */ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, const Value* patch, - SinkFn sink, void* token, SHA_CTX* ctx) { + SinkFn sink, void* token, SHA_CTX* ctx, + const Value* bonus_data) { ssize_t pos = 12; char* header = patch->data; if (patch->size < 12) { @@ -123,6 +124,12 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, // Decompress the source data; the chunk header tells us exactly // how big we expect it to be when decompressed. + // Note: expanded_len will include the bonus data size if + // the patch was constructed with bonus data. The + // deflation will come up 'bonus_size' bytes short; these + // must be appended from the bonus_data value. + size_t bonus_size = (i == 1 && bonus_data != NULL) ? bonus_data->size : 0; + unsigned char* expanded_source = malloc(expanded_len); if (expanded_source == NULL) { printf("failed to allocate %d bytes for expanded_source\n", @@ -153,13 +160,19 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, printf("source inflation returned %d\n", ret); return -1; } - // We should have filled the output buffer exactly. - if (strm.avail_out != 0) { - printf("source inflation short by %d bytes\n", strm.avail_out); + // We should have filled the output buffer exactly, except + // for the bonus_size. + if (strm.avail_out != bonus_size) { + printf("source inflation short by %d bytes\n", strm.avail_out-bonus_size); return -1; } inflateEnd(&strm); + if (bonus_size) { + memcpy(expanded_source + (expanded_len - bonus_size), + bonus_data->data, bonus_size); + } + // Next, apply the bsdiff patch (in memory) to the uncompressed // data. unsigned char* uncompressed_target_data; |