mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Add brotli and tests to CI
Drive-by: - Update sandbox policy - Formatting fixes - Updated comments PiperOrigin-RevId: 453901669 Change-Id: I40e0fbd26525ba564d4e062c79752a0102c48b15
This commit is contained in:
parent
4872ba6569
commit
b11ce4b24a
2
.github/workflows/ubuntu-cmake-contrib.yml
vendored
2
.github/workflows/ubuntu-cmake-contrib.yml
vendored
|
@ -11,7 +11,7 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-20.04]
|
os: [ubuntu-20.04]
|
||||||
contrib: [jsonnet, libraw, libtiff, pffft]
|
contrib: [brotli, jsonnet, libraw, libtiff, pffft]
|
||||||
ignore-errors: [true]
|
ignore-errors: [true]
|
||||||
include:
|
include:
|
||||||
- compiler: clang
|
- compiler: clang
|
||||||
|
|
|
@ -16,6 +16,7 @@ cmake_minimum_required(VERSION 3.13..3.22)
|
||||||
|
|
||||||
project(sapi_brotli CXX)
|
project(sapi_brotli CXX)
|
||||||
include(CTest)
|
include(CTest)
|
||||||
|
include(GoogleTest)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
@ -29,25 +30,22 @@ endif()
|
||||||
|
|
||||||
FetchContent_Declare(libbrotli
|
FetchContent_Declare(libbrotli
|
||||||
GIT_REPOSITORY https://github.com/google/brotli.git
|
GIT_REPOSITORY https://github.com/google/brotli.git
|
||||||
GIT_TAG f4153a09f87cbb9c826d8fc12c74642bb2d879ea
|
GIT_TAG f4153a09f87cbb9c826d8fc12c74642bb2d879ea # 2022-01-10
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(libbrotli)
|
FetchContent_MakeAvailable(libbrotli)
|
||||||
|
|
||||||
set(brotli_INCLUDE_DIR "${brotli_SOURCE_DIR}/c/include")
|
set(brotli_INCLUDE_DIR "${brotli_SOURCE_DIR}/c/include")
|
||||||
configure_file(brotli.gen.h.in brotli.gen.h)
|
configure_file(brotli.gen.h.in brotli.gen.h)
|
||||||
|
|
||||||
add_library(brotli_static INTERFACE)
|
add_library(brotli_static STATIC
|
||||||
target_link_libraries(brotli_static INTERFACE
|
"${SAPI_BINARY_DIR}/sapi_force_cxx_linkage.cc"
|
||||||
brotlicommon-static
|
$<TARGET_OBJECTS:brotlicommon-static>
|
||||||
brotlidec-static
|
$<TARGET_OBJECTS:brotlidec-static>
|
||||||
brotlienc-static
|
$<TARGET_OBJECTS:brotlienc-static>
|
||||||
)
|
)
|
||||||
|
|
||||||
add_sapi_library(
|
add_sapi_library(sapi_brotli
|
||||||
sapi_brotli
|
FUNCTIONS BrotliDecoderCreateInstance
|
||||||
|
|
||||||
FUNCTIONS
|
|
||||||
BrotliDecoderCreateInstance
|
|
||||||
BrotliDecoderSetParameter
|
BrotliDecoderSetParameter
|
||||||
BrotliDecoderDecompressStream
|
BrotliDecoderDecompressStream
|
||||||
BrotliDecoderTakeOutput
|
BrotliDecoderTakeOutput
|
||||||
|
@ -59,8 +57,7 @@ add_sapi_library(
|
||||||
BrotliEncoderSetParameter
|
BrotliEncoderSetParameter
|
||||||
BrotliEncoderDestroyInstance
|
BrotliEncoderDestroyInstance
|
||||||
|
|
||||||
INPUTS
|
INPUTS "${CMAKE_BINARY_DIR}/brotli.gen.h"
|
||||||
"${CMAKE_BINARY_DIR}/brotli.gen.h"
|
|
||||||
|
|
||||||
LIBRARY brotli_static
|
LIBRARY brotli_static
|
||||||
LIBRARY_NAME Brotli
|
LIBRARY_NAME Brotli
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// The generator dosen't handle well complicated structures
|
// The libclang based generator doesn't handle complicated structures and
|
||||||
// and dependencies of brotli. We have to enforce multiple includes.
|
// dependencies of brotli well. We have to enforce multiple includes.
|
||||||
|
|
||||||
#include "${brotli_INCLUDE_DIR}/brotli/port.h"
|
#include "${brotli_INCLUDE_DIR}/brotli/port.h"
|
||||||
#include "${brotli_INCLUDE_DIR}/brotli/types.h"
|
#include "${brotli_INCLUDE_DIR}/brotli/types.h"
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
|
|
||||||
ABSL_FLAG(bool, decompress, false, "decompress");
|
ABSL_FLAG(bool, decompress, false, "decompress");
|
||||||
|
|
||||||
absl::Status CompressInMemory(BrotliSandbox &sandbox,
|
absl::Status CompressInMemory(BrotliSandbox& sandbox,
|
||||||
const std::string &in_file_s,
|
const std::string& in_file_s,
|
||||||
const std::string &out_file_s) {
|
const std::string& out_file_s) {
|
||||||
BrotliEncoder enc(&sandbox);
|
BrotliEncoder enc(&sandbox);
|
||||||
if (!enc.IsInit()) {
|
if (!enc.IsInit()) {
|
||||||
return absl::UnavailableError("Unable to init brotli encoder");
|
return absl::UnavailableError("Unable to init brotli encoder");
|
||||||
|
@ -41,9 +41,9 @@ absl::Status CompressInMemory(BrotliSandbox &sandbox,
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status DecompressInMemory(BrotliSandbox &sandbox,
|
absl::Status DecompressInMemory(BrotliSandbox& sandbox,
|
||||||
const std::string &in_file_s,
|
const std::string& in_file_s,
|
||||||
const std::string &out_file_s) {
|
const std::string& out_file_s) {
|
||||||
BrotliDecoder dec(&sandbox);
|
BrotliDecoder dec(&sandbox);
|
||||||
if (!dec.IsInit()) {
|
if (!dec.IsInit()) {
|
||||||
return absl::UnavailableError("Unable to init brotli decoder");
|
return absl::UnavailableError("Unable to init brotli decoder");
|
||||||
|
@ -60,10 +60,10 @@ absl::Status DecompressInMemory(BrotliSandbox &sandbox,
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
std::string prog_name(argv[0]);
|
std::string prog_name(argv[0]);
|
||||||
sapi::InitLogging(argv[0]);
|
sapi::InitLogging(argv[0]);
|
||||||
std::vector<char *> args = absl::ParseCommandLine(argc, argv);
|
std::vector<char*> args = absl::ParseCommandLine(argc, argv);
|
||||||
|
|
||||||
if (args.size() != 3) {
|
if (args.size() != 3) {
|
||||||
std::cerr << "Usage:\n " << prog_name << " INPUT OUTPUT\n";
|
std::cerr << "Usage:\n " << prog_name << " INPUT OUTPUT\n";
|
||||||
|
|
|
@ -31,7 +31,9 @@ class BrotliSapiSandbox : public BrotliSandbox {
|
||||||
.AllowRead()
|
.AllowRead()
|
||||||
.AllowWrite()
|
.AllowWrite()
|
||||||
.AllowSystemMalloc()
|
.AllowSystemMalloc()
|
||||||
|
.AllowGetPIDs()
|
||||||
.AllowExit()
|
.AllowExit()
|
||||||
|
.BlockSyscallWithErrno(__NR_openat, ENOENT)
|
||||||
.BuildOrDie();
|
.BuildOrDie();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#ifndef CONTRIB_BROTLI_UTILS_UTILS_BROTLI_H_
|
#ifndef CONTRIB_BROTLI_UTILS_UTILS_BROTLI_H_
|
||||||
#define CONTRIB_BROTLI_UTILS_UTILS_BROTLI_H_
|
#define CONTRIB_BROTLI_UTILS_UTILS_BROTLI_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -23,10 +24,12 @@
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "absl/status/statusor.h"
|
#include "absl/status/statusor.h"
|
||||||
|
|
||||||
constexpr size_t kFileMaxSize = 1024 * 1024 * 1024; // 1GB
|
constexpr size_t kFileMaxSize = size_t{1} << 30; // 1GiB
|
||||||
|
|
||||||
std::streamsize GetStreamSize(std::ifstream& stream);
|
std::streamsize GetStreamSize(std::ifstream& stream);
|
||||||
|
|
||||||
absl::StatusOr<std::vector<uint8_t>> ReadFile(const std::string& in_file_s);
|
absl::StatusOr<std::vector<uint8_t>> ReadFile(const std::string& in_file_s);
|
||||||
|
|
||||||
absl::Status WriteFile(const std::string& out_file_s,
|
absl::Status WriteFile(const std::string& out_file_s,
|
||||||
const std::vector<uint8_t>& out_buf);
|
const std::vector<uint8_t>& out_buf);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user