From 0cce9cda0c5cddf947ac42d60886293fab5d0afd Mon Sep 17 00:00:00 2001 From: Sen Jiang Date: Fri, 22 Jan 2016 20:49:07 +0800 Subject: applypatch: Compile libimgpatch for target and host. update_engine need it for the new IMGDIFF operation. Also removed __unused in ApplyImagePatch() as I got error building it for the host, and I think it's dangerous not checking the size of the input. Test: mma Bug: 26628339 Change-Id: I22d4cd55c2c3f87697d6afdf10e8106fef7d1a9c --- applypatch/Android.mk | 24 +++++++++++++++++++++++- applypatch/bspatch.cpp | 1 + applypatch/imgpatch.cpp | 20 +++++++++++++++++++- applypatch/include/applypatch/imgpatch.h | 26 ++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 applypatch/include/applypatch/imgpatch.h diff --git a/applypatch/Android.mk b/applypatch/Android.mk index 93a272997..3cb8bebde 100644 --- a/applypatch/Android.mk +++ b/applypatch/Android.mk @@ -20,13 +20,35 @@ LOCAL_CLANG := true LOCAL_SRC_FILES := applypatch.cpp bspatch.cpp freecache.cpp imgpatch.cpp utils.cpp LOCAL_MODULE := libapplypatch LOCAL_MODULE_TAGS := eng -LOCAL_C_INCLUDES += external/bzip2 external/zlib bootable/recovery +LOCAL_C_INCLUDES += bootable/recovery LOCAL_STATIC_LIBRARIES += libbase libmtdutils libmincrypt libbz libz include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) +LOCAL_CLANG := true +LOCAL_SRC_FILES := bspatch.cpp imgpatch.cpp utils.cpp +LOCAL_MODULE := libimgpatch +LOCAL_C_INCLUDES += bootable/recovery +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include +LOCAL_STATIC_LIBRARIES += libmincrypt libbz libz + +include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_CLANG := true +LOCAL_SRC_FILES := bspatch.cpp imgpatch.cpp utils.cpp +LOCAL_MODULE := libimgpatch +LOCAL_C_INCLUDES += bootable/recovery +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include +LOCAL_STATIC_LIBRARIES += libmincrypt libbz libz + +include $(BUILD_HOST_STATIC_LIBRARY) + +include $(CLEAR_VARS) + LOCAL_CLANG := true LOCAL_SRC_FILES := main.cpp LOCAL_MODULE := applypatch diff --git a/applypatch/bspatch.cpp b/applypatch/bspatch.cpp index 9d201b477..75975ad6d 100644 --- a/applypatch/bspatch.cpp +++ b/applypatch/bspatch.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include 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(const_cast(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(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(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. diff --git a/applypatch/include/applypatch/imgpatch.h b/applypatch/include/applypatch/imgpatch.h new file mode 100644 index 000000000..64d9aa9eb --- /dev/null +++ b/applypatch/include/applypatch/imgpatch.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IMGPATCH_H +#define _IMGPATCH_H + +typedef ssize_t (*SinkFn)(const unsigned char*, ssize_t, void*); + +int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, + const unsigned char* patch_data, ssize_t patch_size, + SinkFn sink, void* token); + +#endif //_IMGPATCH_H -- cgit v1.2.3