Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64686bcd authored by Christopher Ferris's avatar Christopher Ferris Committed by android-build-merger
Browse files

Merge "Add a ZipArchiveStreamEntry class."

am: 9162c149

* commit '9162c149':
  Add a ZipArchiveStreamEntry class.
parents f983e6ce 9162c149
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.
 */

// Read-only stream access to Zip archives entries.
#ifndef LIBZIPARCHIVE_ZIPARCHIVESTREAMENTRY_H_
#define LIBZIPARCHIVE_ZIPARCHIVESTREAMENTRY_H_

#include <vector>

#include <ziparchive/zip_archive.h>

class ZipArchiveStreamEntry {
 public:
  virtual ~ZipArchiveStreamEntry() {}

  virtual const std::vector<uint8_t>* Read() = 0;

  virtual bool Verify() = 0;

  static ZipArchiveStreamEntry* Create(ZipArchiveHandle handle, const ZipEntry& entry);
  static ZipArchiveStreamEntry* CreateRaw(ZipArchiveHandle handle, const ZipEntry& entry);

 protected:
  ZipArchiveStreamEntry(ZipArchiveHandle handle) : handle_(handle) {}

  virtual bool Init(const ZipEntry& entry);

  ZipArchiveHandle handle_;

  uint32_t crc32_;
};

#endif  // LIBZIPARCHIVE_ZIPARCHIVESTREAMENTRY_H_
+47 −23
Original line number Diff line number Diff line
@@ -15,34 +15,46 @@

LOCAL_PATH := $(call my-dir)

source_files := zip_archive.cc zip_writer.cc
test_files := zip_archive_test.cc zip_writer_test.cc entry_name_utils_test.cc
libziparchive_source_files := \
    zip_archive.cc \
    zip_archive_stream_entry.cc \
    zip_writer.cc \

libziparchive_test_files := \
    entry_name_utils_test.cc \
    zip_archive_test.cc \
    zip_writer_test.cc \

# ZLIB_CONST turns on const for input buffers, which is pretty standard.
common_c_flags := -Werror -Wall -DZLIB_CONST
libziparchive_common_c_flags := \
    -DZLIB_CONST \
    -Werror \
    -Wall \

# Incorrectly warns when C++11 empty brace {} initializer is used.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61489
common_cpp_flags := -Wold-style-cast -Wno-missing-field-initializers
libziparchive_common_cpp_flags := \
    -Wold-style-cast \
    -Wno-missing-field-initializers \

include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := ${source_files}
LOCAL_SRC_FILES := $(libziparchive_source_files)
LOCAL_STATIC_LIBRARIES := libz
LOCAL_SHARED_LIBRARIES := libutils libbase
LOCAL_MODULE:= libziparchive
LOCAL_CFLAGS := $(common_c_flags)
LOCAL_CPPFLAGS := $(common_cpp_flags)
LOCAL_CFLAGS := $(libziparchive_common_c_flags)
LOCAL_CPPFLAGS := $(libziparchive_common_cpp_flags)
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := ${source_files}
LOCAL_SRC_FILES := $(libziparchive_source_files)
LOCAL_STATIC_LIBRARIES := libz libutils libbase
LOCAL_MODULE:= libziparchive-host
LOCAL_CFLAGS := $(common_c_flags)
LOCAL_CFLAGS := $(libziparchive_common_c_flags)
LOCAL_CFLAGS_windows := -mno-ms-bitfields
LOCAL_CPPFLAGS := $(common_cpp_flags)
LOCAL_CPPFLAGS := $(libziparchive_common_cpp_flags)

LOCAL_MULTILIB := both
LOCAL_MODULE_HOST_OS := darwin linux windows
@@ -50,12 +62,12 @@ include $(BUILD_HOST_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := ${source_files}
LOCAL_SRC_FILES := $(libziparchive_source_files)
LOCAL_STATIC_LIBRARIES := libutils
LOCAL_SHARED_LIBRARIES := libz-host liblog libbase
LOCAL_MODULE:= libziparchive-host
LOCAL_CFLAGS := $(common_c_flags)
LOCAL_CPPFLAGS := $(common_cpp_flags)
LOCAL_CFLAGS := $(libziparchive_common_c_flags)
LOCAL_CPPFLAGS := $(libziparchive_common_cpp_flags)
LOCAL_MULTILIB := both
include $(BUILD_HOST_SHARED_LIBRARY)

@@ -63,21 +75,33 @@ include $(BUILD_HOST_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ziparchive-tests
LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS := $(common_c_flags)
LOCAL_CPPFLAGS := $(common_cpp_flags)
LOCAL_SRC_FILES := $(test_files)
LOCAL_SHARED_LIBRARIES := liblog libbase
LOCAL_STATIC_LIBRARIES := libziparchive libz libutils
LOCAL_CFLAGS := $(libziparchive_common_c_flags)
LOCAL_CPPFLAGS := $(libziparchive_common_cpp_flags)
LOCAL_SRC_FILES := $(libziparchive_test_files)
LOCAL_SHARED_LIBRARIES := \
    libbase \
    liblog \

LOCAL_STATIC_LIBRARIES := \
    libziparchive \
    libz \
    libutils \

include $(BUILD_NATIVE_TEST)

include $(CLEAR_VARS)
LOCAL_MODULE := ziparchive-tests-host
LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS := $(common_c_flags)
LOCAL_CPPFLAGS := -Wno-unnamed-type-template-args $(common_cpp_flags)
LOCAL_SRC_FILES := $(test_files)
LOCAL_SHARED_LIBRARIES := libziparchive-host liblog libbase
LOCAL_CFLAGS := $(libziparchive_common_c_flags)
LOCAL_CPPFLAGS := -Wno-unnamed-type-template-args $(libziparchive_common_cpp_flags)
LOCAL_SRC_FILES := $(libziparchive_test_files)
LOCAL_SHARED_LIBRARIES := \
    libziparchive-host \
    liblog \
    libbase \

LOCAL_STATIC_LIBRARIES := \
    libutils \
    libz \
    libutils

include $(BUILD_HOST_NATIVE_TEST)
+320 B

File added.

No diff preview for this file type.

+308 KiB

File added.

No diff preview for this file type.

+2 −38
Original line number Diff line number Diff line
@@ -36,11 +36,12 @@
#include "log/log.h"
#include "utils/Compat.h"
#include "utils/FileMap.h"
#include "ziparchive/zip_archive.h"
#include "zlib.h"

#include "entry_name_utils-inl.h"
#include "zip_archive_common.h"
#include "ziparchive/zip_archive.h"
#include "zip_archive_private.h"

using android::base::get_unaligned;

@@ -134,43 +135,6 @@ static const int32_t kErrorMessageLowerBound = -13;
 * every page that the Central Directory touches.  Easier to tuck a copy
 * of the string length into the hash table entry.
 */
struct ZipArchive {
  /* open Zip archive */
  const int fd;
  const bool close_file;

  /* mapped central directory area */
  off64_t directory_offset;
  android::FileMap directory_map;

  /* number of entries in the Zip archive */
  uint16_t num_entries;

  /*
   * We know how many entries are in the Zip archive, so we can have a
   * fixed-size hash table. We define a load factor of 0.75 and overallocat
   * so the maximum number entries can never be higher than
   * ((4 * UINT16_MAX) / 3 + 1) which can safely fit into a uint32_t.
   */
  uint32_t hash_table_size;
  ZipString* hash_table;

  ZipArchive(const int fd, bool assume_ownership) :
      fd(fd),
      close_file(assume_ownership),
      directory_offset(0),
      num_entries(0),
      hash_table_size(0),
      hash_table(NULL) {}

  ~ZipArchive() {
    if (close_file && fd >= 0) {
      close(fd);
    }

    free(hash_table);
  }
};

/*
 * Round up to the next highest power of 2.
Loading