summaryrefslogtreecommitdiffstats
path: root/applypatch/imgpatch.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-01-29 05:58:59 +0100
committerTao Bao <tbao@google.com>2016-01-29 05:58:59 +0100
commit484c49e99ec501960672a1dcceb38dbb7bde1956 (patch)
tree1538cb19c557e756a3ff6c9ab17d73001c4b8c43 /applypatch/imgpatch.cpp
parentMerge "edify: accept long string literal." am: d379b4410b (diff)
parentMerge "applypatch: Compile libimgpatch for target and host." (diff)
downloadandroid_bootable_recovery-484c49e99ec501960672a1dcceb38dbb7bde1956.tar
android_bootable_recovery-484c49e99ec501960672a1dcceb38dbb7bde1956.tar.gz
android_bootable_recovery-484c49e99ec501960672a1dcceb38dbb7bde1956.tar.bz2
android_bootable_recovery-484c49e99ec501960672a1dcceb38dbb7bde1956.tar.lz
android_bootable_recovery-484c49e99ec501960672a1dcceb38dbb7bde1956.tar.xz
android_bootable_recovery-484c49e99ec501960672a1dcceb38dbb7bde1956.tar.zst
android_bootable_recovery-484c49e99ec501960672a1dcceb38dbb7bde1956.zip
Diffstat (limited to 'applypatch/imgpatch.cpp')
-rw-r--r--applypatch/imgpatch.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp
index 26888f8ee..3e72b2cb5 100644
--- a/applypatch/imgpatch.cpp
+++ b/applypatch/imgpatch.cpp
@@ -31,13 +31,22 @@
#include "imgdiff.h"
#include "utils.h"
+int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
+ const unsigned char* patch_data, ssize_t patch_size,
+ SinkFn sink, void* token) {
+ Value patch = {VAL_BLOB, patch_size,
+ reinterpret_cast<char*>(const_cast<unsigned char*>(patch_data))};
+ return ApplyImagePatch(
+ old_data, old_size, &patch, sink, token, nullptr, nullptr);
+}
+
/*
* Apply the patch given in 'patch_filename' to the source data given
* by (old_data, old_size). Write the patched output to the 'output'
* file, and update the SHA context with the output data as well.
* Return 0 on success.
*/
-int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size __unused,
+int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
const Value* patch,
SinkFn sink, void* token, SHA_CTX* ctx,
const Value* bonus_data) {
@@ -80,6 +89,10 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size __unused,
size_t src_len = Read8(normal_header+8);
size_t patch_offset = Read8(normal_header+16);
+ if (src_start + src_len > static_cast<size_t>(old_size)) {
+ printf("source data too short\n");
+ return -1;
+ }
ApplyBSDiffPatch(old_data + src_start, src_len,
patch, patch_offset, sink, token, ctx);
} else if (type == CHUNK_RAW) {
@@ -123,6 +136,11 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size __unused,
int memLevel = Read4(deflate_header+52);
int strategy = Read4(deflate_header+56);
+ if (src_start + src_len > static_cast<size_t>(old_size)) {
+ printf("source data too short\n");
+ return -1;
+ }
+
// Decompress the source data; the chunk header tells us exactly
// how big we expect it to be when decompressed.