am 65937e9b: Merge "Prevent unaligned read in libziparchive."
* commit '65937e9bac665e216268d7341094afcaa52ef8c1': Prevent unaligned read in libziparchive.
This commit is contained in:
commit
1110aa7826
2 changed files with 21 additions and 22 deletions
|
|
@ -21,7 +21,7 @@ include $(CLEAR_VARS)
|
||||||
LOCAL_CPP_EXTENSION := .cc
|
LOCAL_CPP_EXTENSION := .cc
|
||||||
LOCAL_SRC_FILES := ${source_files}
|
LOCAL_SRC_FILES := ${source_files}
|
||||||
LOCAL_STATIC_LIBRARIES := libz
|
LOCAL_STATIC_LIBRARIES := libz
|
||||||
LOCAL_SHARED_LIBRARIES := libutils
|
LOCAL_SHARED_LIBRARIES := libutils libbase
|
||||||
LOCAL_MODULE:= libziparchive
|
LOCAL_MODULE:= libziparchive
|
||||||
LOCAL_CFLAGS := -Werror -Wall
|
LOCAL_CFLAGS := -Werror -Wall
|
||||||
LOCAL_CPPFLAGS := -Wold-style-cast
|
LOCAL_CPPFLAGS := -Wold-style-cast
|
||||||
|
|
@ -30,7 +30,7 @@ include $(BUILD_STATIC_LIBRARY)
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_CPP_EXTENSION := .cc
|
LOCAL_CPP_EXTENSION := .cc
|
||||||
LOCAL_SRC_FILES := ${source_files}
|
LOCAL_SRC_FILES := ${source_files}
|
||||||
LOCAL_STATIC_LIBRARIES := libz libutils
|
LOCAL_STATIC_LIBRARIES := libz libutils libbase
|
||||||
LOCAL_MODULE:= libziparchive-host
|
LOCAL_MODULE:= libziparchive-host
|
||||||
LOCAL_CFLAGS := -Werror
|
LOCAL_CFLAGS := -Werror
|
||||||
ifneq ($(strip $(USE_MINGW)),)
|
ifneq ($(strip $(USE_MINGW)),)
|
||||||
|
|
@ -43,7 +43,7 @@ include $(CLEAR_VARS)
|
||||||
LOCAL_CPP_EXTENSION := .cc
|
LOCAL_CPP_EXTENSION := .cc
|
||||||
LOCAL_SRC_FILES := ${source_files}
|
LOCAL_SRC_FILES := ${source_files}
|
||||||
LOCAL_STATIC_LIBRARIES := libz libutils
|
LOCAL_STATIC_LIBRARIES := libz libutils
|
||||||
LOCAL_SHARED_LIBRARIES := liblog
|
LOCAL_SHARED_LIBRARIES := liblog libbase
|
||||||
LOCAL_MODULE:= libziparchive-host
|
LOCAL_MODULE:= libziparchive-host
|
||||||
LOCAL_CFLAGS := -Werror
|
LOCAL_CFLAGS := -Werror
|
||||||
LOCAL_MULTILIB := both
|
LOCAL_MULTILIB := both
|
||||||
|
|
@ -55,7 +55,7 @@ LOCAL_MODULE := ziparchive-tests
|
||||||
LOCAL_CPP_EXTENSION := .cc
|
LOCAL_CPP_EXTENSION := .cc
|
||||||
LOCAL_CFLAGS := -Werror
|
LOCAL_CFLAGS := -Werror
|
||||||
LOCAL_SRC_FILES := zip_archive_test.cc entry_name_utils_test.cc
|
LOCAL_SRC_FILES := zip_archive_test.cc entry_name_utils_test.cc
|
||||||
LOCAL_SHARED_LIBRARIES := liblog
|
LOCAL_SHARED_LIBRARIES := liblog libbase
|
||||||
LOCAL_STATIC_LIBRARIES := libziparchive libz libutils
|
LOCAL_STATIC_LIBRARIES := libziparchive libz libutils
|
||||||
include $(BUILD_NATIVE_TEST)
|
include $(BUILD_NATIVE_TEST)
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ LOCAL_CFLAGS += \
|
||||||
-Werror \
|
-Werror \
|
||||||
-Wno-unnamed-type-template-args
|
-Wno-unnamed-type-template-args
|
||||||
LOCAL_SRC_FILES := zip_archive_test.cc entry_name_utils_test.cc
|
LOCAL_SRC_FILES := zip_archive_test.cc entry_name_utils_test.cc
|
||||||
LOCAL_SHARED_LIBRARIES := libziparchive-host liblog
|
LOCAL_SHARED_LIBRARIES := libziparchive-host liblog libbase
|
||||||
LOCAL_STATIC_LIBRARIES := \
|
LOCAL_STATIC_LIBRARIES := \
|
||||||
libz \
|
libz \
|
||||||
libutils
|
libutils
|
||||||
|
|
|
||||||
|
|
@ -18,27 +18,29 @@
|
||||||
* Read-only access to Zip archives, with minimal heap allocation.
|
* Read-only access to Zip archives, with minimal heap allocation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <log/log.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utils/Compat.h>
|
|
||||||
#include <utils/FileMap.h>
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
#include <JNIHelp.h> // TEMP_FAILURE_RETRY may or may not be in unistd
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "base/macros.h" // TEMP_FAILURE_RETRY may or may not be in unistd
|
||||||
|
#include "base/memory.h"
|
||||||
|
#include "log/log.h"
|
||||||
|
#include "utils/Compat.h"
|
||||||
|
#include "utils/FileMap.h"
|
||||||
|
#include "zlib.h"
|
||||||
|
|
||||||
#include "entry_name_utils-inl.h"
|
#include "entry_name_utils-inl.h"
|
||||||
#include "ziparchive/zip_archive.h"
|
#include "ziparchive/zip_archive.h"
|
||||||
|
|
||||||
|
using android::base::get_unaligned;
|
||||||
|
|
||||||
// This is for windows. If we don't open a file in binary mode, weird
|
// This is for windows. If we don't open a file in binary mode, weird
|
||||||
// things will happen.
|
// things will happen.
|
||||||
|
|
@ -46,11 +48,6 @@
|
||||||
#define O_BINARY 0
|
#define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
|
|
||||||
TypeName(); \
|
|
||||||
TypeName(const TypeName&); \
|
|
||||||
void operator=(const TypeName&)
|
|
||||||
|
|
||||||
// The "end of central directory" (EOCD) record. Each archive
|
// The "end of central directory" (EOCD) record. Each archive
|
||||||
// contains exactly once such record which appears at the end of
|
// contains exactly once such record which appears at the end of
|
||||||
// the archive. It contains archive wide information like the
|
// the archive. It contains archive wide information like the
|
||||||
|
|
@ -462,10 +459,12 @@ static int32_t MapCentralDirectory0(int fd, const char* debug_file_name,
|
||||||
*/
|
*/
|
||||||
int i = read_amount - sizeof(EocdRecord);
|
int i = read_amount - sizeof(EocdRecord);
|
||||||
for (; i >= 0; i--) {
|
for (; i >= 0; i--) {
|
||||||
if (scan_buffer[i] == 0x50 &&
|
if (scan_buffer[i] == 0x50) {
|
||||||
((*reinterpret_cast<uint32_t*>(&scan_buffer[i])) == EocdRecord::kSignature)) {
|
uint32_t* sig_addr = reinterpret_cast<uint32_t*>(&scan_buffer[i]);
|
||||||
ALOGV("+++ Found EOCD at buf+%d", i);
|
if (get_unaligned<uint32_t>(sig_addr) == EocdRecord::kSignature) {
|
||||||
break;
|
ALOGV("+++ Found EOCD at buf+%d", i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue