diff --git a/.github/workflows/ubuntu-cmake-contrib.yml b/.github/workflows/ubuntu-cmake-contrib.yml index faf86bc..146ee15 100644 --- a/.github/workflows/ubuntu-cmake-contrib.yml +++ b/.github/workflows/ubuntu-cmake-contrib.yml @@ -1,4 +1,4 @@ -name: CMake Ubuntu Contrib +name: CMake Ubuntu Contrb on: [push, pull_request] @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-20.04] - contrib: [brotli, jsonnet, libraw, libtiff, pffft] + contrib: [brotli, jsonnet, libraw, lodepng, libtiff, pffft] ignore-errors: [true] include: - compiler: clang diff --git a/contrib/lodepng/CMakeLists.txt b/contrib/lodepng/CMakeLists.txt new file mode 100644 index 0000000..8ddc5a9 --- /dev/null +++ b/contrib/lodepng/CMakeLists.txt @@ -0,0 +1,90 @@ +# Copyright 2020 Google LLC +# +# 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 +# +# https://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. + +cmake_minimum_required(VERSION 3.13..3.22) + +project(lodepng_sapi C CXX) +include(CTest) +include(GoogleTest) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED 17) + +if(NOT TARGET sapi::sapi) + set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree") + add_subdirectory("${SAPI_ROOT}" + "${CMAKE_BINARY_DIR}/sandboxed-api-build" + EXCLUDE_FROM_ALL) +endif() + +FetchContent_Declare(lodepng + GIT_REPOSITORY https://github.com/lvandeve/lodepng.git + GIT_TAG 3d9fda048393e32cc11d0c3d3caba0a85c1c2dfe # 2022-05-22 +) +FetchContent_MakeAvailable(lodepng) + +# lodepng can be compiled as both C++ and C. We want the latter, so enforce +# C as the language. set_source_files_properties() does not work here. +configure_file(lodepng.gen.h.in + "${lodepng_BINARY_DIR}/lodepng.gen.h") +configure_file("${lodepng_SOURCE_DIR}/lodepng.cpp" + "${lodepng_BINARY_DIR}/lodepng.c" COPYONLY) + +# Build static library +add_library(lodepng STATIC + "${lodepng_BINARY_DIR}/lodepng.c" + "${lodepng_BINARY_DIR}/lodepng.gen.h" + "${lodepng_SOURCE_DIR}/lodepng.h" +) +target_include_directories(lodepng PUBLIC + "${lodepng_BINARY_DIR}" + "${lodepng_SOURCE_DIR}" +) +target_compile_definitions(lodepng PUBLIC + LODEPNG_NO_COMPILE_CPP +) + +# Build SAPI library +add_sapi_library(lodepng_sapi + FUNCTIONS lodepng_decode_memory + lodepng_decode32 + lodepng_decode24 + + lodepng_decode_file + lodepng_decode32_file + lodepng_decode24_file + + lodepng_encode_memory + lodepng_encode32 + lodepng_encode24 + + lodepng_encode_file + lodepng_encode32_file + lodepng_encode24_file + + lodepng_save_file + lodepng_load_file + + INPUTS "${lodepng_BINARY_DIR}/lodepng.gen.h" + LIBRARY lodepng + LIBRARY_NAME Lodepng + NAMESPACE "" +) +add_library(sapi_contrib::lodepng ALIAS lodepng_sapi) +target_include_directories(lodepng_sapi INTERFACE + "${PROJECT_BINARY_DIR}" # To find the generated SAPI header +) + +# Examples and tests +add_subdirectory(examples) diff --git a/oss-internship-2020/lodepng/README.md b/contrib/lodepng/README.md similarity index 88% rename from oss-internship-2020/lodepng/README.md rename to contrib/lodepng/README.md index e418f6e..46549b9 100644 --- a/oss-internship-2020/lodepng/README.md +++ b/contrib/lodepng/README.md @@ -1,6 +1,10 @@ # LodePNG Sandboxed API -Sandboxed version of the [LodePNG](https://github.com/lvandeve/lodepng) library, using [Sandboxed API](https://github.com/google/sandboxed-api) +This library was sandboxed as part of Google's summer 2020 internship program +([blog post](https://security.googleblog.com/2020/12/improving-open-source-security-during.html)). + +This directory contains a sandbox for the +[LodePNG](https://github.com/lvandeve/lodepng) library. ## Details @@ -14,8 +18,7 @@ In the **patches** folder there is a patch file that adds `extern "C"` to the re ## Build -First, run `git submodule update --init --recursive` to update submodules. -After this, run the following commands: +Run the following commands: `mkdir -p build && cd build` diff --git a/contrib/lodepng/examples/CMakeLists.txt b/contrib/lodepng/examples/CMakeLists.txt new file mode 100644 index 0000000..debd2fb --- /dev/null +++ b/contrib/lodepng/examples/CMakeLists.txt @@ -0,0 +1,67 @@ +# Copyright 2020 Google LLC +# +# 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 +# +# https://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. + +if(SAPI_BUILD_EXAMPLES) + # Build the unsandboxed main + add_executable(lodepng_unsandboxed + main_unsandboxed.cc + helpers.cc + ) + target_link_libraries(lodepng_unsandboxed PRIVATE + lodepng + sapi::logging + sapi::sapi + sapi::temp_file + sapi::file_base + sapi::fileops + ) + + # Build the sandboxed main + add_executable(lodepng_sandboxed + main_sandboxed.cc + sandbox.h + helpers.cc + ) + target_link_libraries(lodepng_sandboxed PRIVATE + sapi_contrib::lodepng + sapi::logging + sapi::sapi + sapi::temp_file + sapi::fileops + sapi::vars + sapi::status + ) +endif() + +if(BUILD_TESTING AND SAPI_BUILD_TESTING) + add_executable(main_unit_test + main_unit_test.cc + helpers.cc + ) + target_link_libraries(main_unit_test PRIVATE + sapi_contrib::lodepng + absl::memory + absl::strings + absl::time + sapi::flags + sapi::logging + sapi::sapi + sapi::temp_file + sapi::fileops + sapi::status + sapi::test_main + sapi::vars + ) + gtest_discover_tests(main_unit_test) +endif() diff --git a/oss-internship-2020/lodepng/examples/helpers.cc b/contrib/lodepng/examples/helpers.cc similarity index 90% rename from oss-internship-2020/lodepng/examples/helpers.cc rename to contrib/lodepng/examples/helpers.cc index 0d909e7..c18808b 100644 --- a/oss-internship-2020/lodepng/examples/helpers.cc +++ b/contrib/lodepng/examples/helpers.cc @@ -34,11 +34,11 @@ std::vector GenerateValues() { } std::string CreateTempDirAtCWD() { - std::string cwd = sandbox2::file_util::fileops::GetCWD(); + std::string cwd = sapi::file_util::fileops::GetCWD(); CHECK(!cwd.empty()) << "Could not get current working directory"; cwd.append("/"); - absl::StatusOr result = sandbox2::CreateTempDir(cwd); + absl::StatusOr result = sapi::CreateTempDir(cwd); CHECK(result.ok()) << "Could not create temporary directory"; return result.value(); } diff --git a/oss-internship-2020/lodepng/examples/helpers.h b/contrib/lodepng/examples/helpers.h similarity index 90% rename from oss-internship-2020/lodepng/examples/helpers.h rename to contrib/lodepng/examples/helpers.h index 4803dde..08ed330 100644 --- a/oss-internship-2020/lodepng/examples/helpers.h +++ b/contrib/lodepng/examples/helpers.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LODEPNG_EXAMPLES_HELPERS_H_ -#define LODEPNG_EXAMPLES_HELPERS_H_ +#ifndef CONTRIB_LODEPNG_EXAMPLES_HELPERS_H_ +#define CONTRIB_LODEPNG_EXAMPLES_HELPERS_H_ #include #include @@ -36,4 +36,4 @@ std::vector GenerateValues(); // the path. std::string CreateTempDirAtCWD(); -#endif // LODEPNG_EXAMPLES_HELPERS_H_ +#endif // CONTRIB_LODEPNG_EXAMPLES_HELPERS_H_ diff --git a/oss-internship-2020/lodepng/examples/main_sandboxed.cc b/contrib/lodepng/examples/main_sandboxed.cc similarity index 94% rename from oss-internship-2020/lodepng/examples/main_sandboxed.cc rename to contrib/lodepng/examples/main_sandboxed.cc index 4938808..e969a72 100644 --- a/oss-internship-2020/lodepng/examples/main_sandboxed.cc +++ b/contrib/lodepng/examples/main_sandboxed.cc @@ -14,10 +14,10 @@ #include -#include #include "helpers.h" // NOLINT(build/include) #include "sandbox.h" // NOLINT(build/include) #include "absl/status/statusor.h" +#include "sandboxed_api/util/logging.h" void EncodeDecodeOneStep(SapiLodepngSandbox& sandbox, LodepngApi& api) { // Generate the values. @@ -71,7 +71,7 @@ void EncodeDecodeOneStep(SapiLodepngSandbox& sandbox, LodepngApi& api) { << "Values differ"; // Free the memory allocated inside the sandbox. - CHECK(sandbox.GetRpcChannel()->Free(sapi_image_ptr.GetValue()).ok()) + CHECK(sandbox.rpc_channel()->Free(sapi_image_ptr.GetValue()).ok()) << "Could not free memory inside sandboxed process"; } @@ -163,11 +163,11 @@ void EncodeDecodeTwoSteps(SapiLodepngSandbox& sandbox, LodepngApi& api) { << "Values differ"; // Free the memory allocated inside the sandbox. - CHECK(sandbox.GetRpcChannel()->Free(sapi_png_ptr.GetValue()).ok()) + CHECK(sandbox.rpc_channel()->Free(sapi_png_ptr.GetValue()).ok()) << "Could not free memory inside sandboxed process"; - CHECK(sandbox.GetRpcChannel()->Free(sapi_png_ptr2.GetValue()).ok()) + CHECK(sandbox.rpc_channel()->Free(sapi_png_ptr2.GetValue()).ok()) << "Could not free memory inside sandboxed process"; - CHECK(sandbox.GetRpcChannel()->Free(sapi_png_ptr3.GetValue()).ok()) + CHECK(sandbox.rpc_channel()->Free(sapi_png_ptr3.GetValue()).ok()) << "Could not free memory inside sandboxed process"; } @@ -175,7 +175,7 @@ int main(int argc, char* argv[]) { sapi::InitLogging(argv[0]); const std::string images_path = CreateTempDirAtCWD(); - CHECK(sandbox2::file_util::fileops::Exists(images_path, false)) + CHECK(sapi::file_util::fileops::Exists(images_path, false)) << "Temporary directory does not exist"; SapiLodepngSandbox sandbox(images_path); @@ -186,7 +186,7 @@ int main(int argc, char* argv[]) { EncodeDecodeOneStep(sandbox, api); EncodeDecodeTwoSteps(sandbox, api); - if (sandbox2::file_util::fileops::DeleteRecursively(images_path)) { + if (sapi::file_util::fileops::DeleteRecursively(images_path)) { LOG(WARNING) << "Temporary folder could not be deleted"; } diff --git a/oss-internship-2020/lodepng/examples/main_unit_test.cc b/contrib/lodepng/examples/main_unit_test.cc similarity index 87% rename from oss-internship-2020/lodepng/examples/main_unit_test.cc rename to contrib/lodepng/examples/main_unit_test.cc index 4a42566..1f7ca8f 100644 --- a/oss-internship-2020/lodepng/examples/main_unit_test.cc +++ b/contrib/lodepng/examples/main_unit_test.cc @@ -26,11 +26,10 @@ namespace { TEST(HelpersTest, CreateTempDirAtCWD) { const std::string images_path = CreateTempDirAtCWD(); - ASSERT_THAT(sandbox2::file_util::fileops::Exists(images_path, false), - IsTrue()) + ASSERT_THAT(sapi::file_util::fileops::Exists(images_path, false), IsTrue()) << "Temporary directory does not exist"; - EXPECT_THAT(sandbox2::file_util::fileops::DeleteRecursively(images_path), + EXPECT_THAT(sapi::file_util::fileops::DeleteRecursively(images_path), IsTrue()) << "Temporary directory could not be deleted"; } @@ -41,14 +40,13 @@ TEST(HelpersTest, GenerateValues) { TEST(LodePngTest, Init) { const std::string images_path = CreateTempDirAtCWD(); - ASSERT_THAT(sandbox2::file_util::fileops::Exists(images_path, false), - IsTrue()) + ASSERT_THAT(sapi::file_util::fileops::Exists(images_path, false), IsTrue()) << "Temporary directory does not exist"; SapiLodepngSandbox sandbox(images_path); ASSERT_THAT(sandbox.Init(), IsOk()) << "Error during sandbox init"; - EXPECT_THAT(sandbox2::file_util::fileops::DeleteRecursively(images_path), + EXPECT_THAT(sapi::file_util::fileops::DeleteRecursively(images_path), IsTrue()) << "Temporary directory could not be deleted"; } @@ -57,8 +55,7 @@ TEST(LodePngTest, Init) { // initial values. TEST(LodePngTest, EncodeDecodeOneStep) { const std::string images_path = CreateTempDirAtCWD(); - ASSERT_THAT(sandbox2::file_util::fileops::Exists(images_path, false), - IsTrue()) + ASSERT_THAT(sapi::file_util::fileops::Exists(images_path, false), IsTrue()) << "Temporary directory does not exist"; SapiLodepngSandbox sandbox(images_path); @@ -105,10 +102,10 @@ TEST(LodePngTest, EncodeDecodeOneStep) { IsTrue()) << "Values differ"; - EXPECT_THAT(sandbox.GetRpcChannel()->Free(sapi_image_ptr.GetValue()), IsOk()) + EXPECT_THAT(sandbox.rpc_channel()->Free(sapi_image_ptr.GetValue()), IsOk()) << "Could not free memory inside sandboxed process"; - EXPECT_THAT(sandbox2::file_util::fileops::DeleteRecursively(images_path), + EXPECT_THAT(sapi::file_util::fileops::DeleteRecursively(images_path), IsTrue()) << "Temporary directory could not be deleted"; } @@ -118,8 +115,7 @@ TEST(LodePngTest, EncodeDecodeOneStep) { // memory and then getting the actual pixel values. TEST(LodePngTest, EncodeDecodeTwoSteps) { const std::string images_path = CreateTempDirAtCWD(); - ASSERT_THAT(sandbox2::file_util::fileops::Exists(images_path, false), - IsTrue()) + ASSERT_THAT(sapi::file_util::fileops::Exists(images_path, false), IsTrue()) << "Temporary directory does not exist"; SapiLodepngSandbox sandbox(images_path); @@ -201,11 +197,11 @@ TEST(LodePngTest, EncodeDecodeTwoSteps) { IsTrue()) << "Values differ"; - EXPECT_THAT(sandbox.GetRpcChannel()->Free(sapi_png_ptr.GetValue()), IsOk()); - EXPECT_THAT(sandbox.GetRpcChannel()->Free(sapi_png_ptr2.GetValue()), IsOk()); - EXPECT_THAT(sandbox.GetRpcChannel()->Free(sapi_png_ptr3.GetValue()), IsOk()); + EXPECT_THAT(sandbox.rpc_channel()->Free(sapi_png_ptr.GetValue()), IsOk()); + EXPECT_THAT(sandbox.rpc_channel()->Free(sapi_png_ptr2.GetValue()), IsOk()); + EXPECT_THAT(sandbox.rpc_channel()->Free(sapi_png_ptr3.GetValue()), IsOk()); - EXPECT_THAT(sandbox2::file_util::fileops::DeleteRecursively(images_path), + EXPECT_THAT(sapi::file_util::fileops::DeleteRecursively(images_path), IsTrue()) << "Temporary directory could not be deleted"; } diff --git a/oss-internship-2020/lodepng/examples/main_unsandboxed.cc b/contrib/lodepng/examples/main_unsandboxed.cc similarity index 89% rename from oss-internship-2020/lodepng/examples/main_unsandboxed.cc rename to contrib/lodepng/examples/main_unsandboxed.cc index 4f1ceaf..7882473 100644 --- a/oss-internship-2020/lodepng/examples/main_unsandboxed.cc +++ b/contrib/lodepng/examples/main_unsandboxed.cc @@ -14,10 +14,10 @@ #include -#include -#include "helpers.h" // NOLINT(build/include) -#include "lodepng.h" // NOLINT(build/include) +#include "helpers.h" // NOLINT(build/include) +#include "lodepng.gen.h" // NOLINT(build/include) #include "sandboxed_api/util/fileops.h" +#include "sandboxed_api/util/logging.h" #include "sandboxed_api/util/path.h" void EncodeDecodeOneStep(const std::string& images_path) { @@ -26,7 +26,7 @@ void EncodeDecodeOneStep(const std::string& images_path) { // Encode the image. const std::string filename = - sandbox2::file::JoinPath(images_path, "/out_generated1.png"); + sapi::file::JoinPath(images_path, "/out_generated1.png"); unsigned int result = lodepng_encode32_file(filename.c_str(), image.data(), kWidth, kHeight); @@ -57,7 +57,7 @@ void EncodeDecodeTwoSteps(const std::string& images_path) { // Encode the image into memory first. const std::string filename = - sandbox2::file::JoinPath(images_path, "/out_generated2.png"); + sapi::file::JoinPath(images_path, "/out_generated2.png"); uint8_t* png; size_t pngsize; @@ -102,13 +102,13 @@ int main(int argc, char* argv[]) { sapi::InitLogging(argv[0]); const std::string images_path = CreateTempDirAtCWD(); - CHECK(sandbox2::file_util::fileops::Exists(images_path, false)) + CHECK(sapi::file_util::fileops::Exists(images_path, false)) << "Temporary directory does not exist"; EncodeDecodeOneStep(images_path); EncodeDecodeTwoSteps(images_path); - if (sandbox2::file_util::fileops::DeleteRecursively(images_path)) { + if (sapi::file_util::fileops::DeleteRecursively(images_path)) { LOG(WARNING) << "Temporary folder could not be deleted"; } diff --git a/oss-internship-2020/lodepng/examples/sandbox.h b/contrib/lodepng/examples/sandbox.h similarity index 89% rename from oss-internship-2020/lodepng/examples/sandbox.h rename to contrib/lodepng/examples/sandbox.h index 27cd085..5aab04b 100644 --- a/oss-internship-2020/lodepng/examples/sandbox.h +++ b/contrib/lodepng/examples/sandbox.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef LODEPNG_EXAMPLES_SANDBOX_H_ -#define LODEPNG_EXAMPLES_SANDBOX_H_ +#ifndef CONTRIB_LODEPNG_EXAMPLES_SANDBOX_H_ +#define CONTRIB_LODEPNG_EXAMPLES_SANDBOX_H_ #include @@ -34,6 +34,7 @@ class SapiLodepngSandbox : public LodepngSandbox { .AllowSystemMalloc() .AllowExit() .AllowStat() + .AllowGetPIDs() .AddDirectoryAt(images_path_, "/output/", /*is_ro=*/false) .AllowSyscalls({ __NR_futex, @@ -46,4 +47,4 @@ class SapiLodepngSandbox : public LodepngSandbox { const std::string images_path_; }; -#endif // LODEPNG_EXAMPLES_SANDBOX__ +#endif // CONTRIB_LODEPNG_EXAMPLES_SANDBOX__ diff --git a/contrib/lodepng/lodepng.gen.h.in b/contrib/lodepng/lodepng.gen.h.in new file mode 100644 index 0000000..264c13b --- /dev/null +++ b/contrib/lodepng/lodepng.gen.h.in @@ -0,0 +1,24 @@ +// Copyright 2022 Google LLC +// +// 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 +// +// https://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 CONTRIB_LODEPNG_LODEPNG_GEN_H_ +#define CONTRIB_LODEPNG_LODEPNG_GEN_H_ + +extern "C" { + +#include "${lodepng_SOURCE_DIR}/lodepng.h" + +} + +#endif // CONTRIB_LODEPNG_LODEPNG_GEN_H_ diff --git a/oss-internship-2020/lodepng/.gitignore b/oss-internship-2020/lodepng/.gitignore deleted file mode 100644 index 436efe7..0000000 --- a/oss-internship-2020/lodepng/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -build/ -.clang-format -.cache diff --git a/oss-internship-2020/lodepng/CMakeLists.txt b/oss-internship-2020/lodepng/CMakeLists.txt deleted file mode 100644 index 45cf6b1..0000000 --- a/oss-internship-2020/lodepng/CMakeLists.txt +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2020 Google LLC -# -# 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 -# -# https://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. - -cmake_minimum_required(VERSION 3.16) - -project(lodepng_sapi CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED 17) - -# Apply the patches to the header file. -add_custom_command( - OUTPUT "${PROJECT_BINARY_DIR}/lodepng/lodepng.h" "${PROJECT_BINARY_DIR}/lodepng/lodepng.cpp" - COMMENT "Applying patch to header file." - COMMAND cp -r "${PROJECT_SOURCE_DIR}/lodepng" "${PROJECT_BINARY_DIR}/" - COMMAND cp "${PROJECT_SOURCE_DIR}/patches/header.patch" "${PROJECT_BINARY_DIR}/lodepng/" - COMMAND cd "${PROJECT_BINARY_DIR}/lodepng" && patch < header.patch -) - -# Build static library. -add_library(lodepng STATIC - "${PROJECT_BINARY_DIR}/lodepng/lodepng.cpp" - "${PROJECT_BINARY_DIR}/lodepng/lodepng.h" -) - -target_include_directories(lodepng PUBLIC "${PROJECT_BINARY_DIR}/lodepng") - -# Build SAPI library -set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree") - -add_subdirectory("${SAPI_ROOT}" - "${CMAKE_BINARY_DIR}/sandboxed-api-build" - EXCLUDE_FROM_ALL -) - -add_sapi_library( - lodepng_sapi - - FUNCTIONS - lodepng_decode_memory - lodepng_decode32 - lodepng_decode24 - - lodepng_decode_file - lodepng_decode32_file - lodepng_decode24_file - - lodepng_encode_memory - lodepng_encode32 - lodepng_encode24 - - lodepng_encode_file - lodepng_encode32_file - lodepng_encode24_file - - lodepng_save_file - lodepng_load_file - - INPUTS "${PROJECT_BINARY_DIR}/lodepng/lodepng.h" - LIBRARY lodepng - LIBRARY_NAME Lodepng - NAMESPACE "" -) - -target_include_directories(lodepng_sapi INTERFACE - "${PROJECT_BINARY_DIR}" # To find the generated SAPI header -) - -add_subdirectory(examples) diff --git a/oss-internship-2020/lodepng/examples/CMakeLists.txt b/oss-internship-2020/lodepng/examples/CMakeLists.txt deleted file mode 100644 index 2cff361..0000000 --- a/oss-internship-2020/lodepng/examples/CMakeLists.txt +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright 2020 Google LLC -# -# 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 -# -# https://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. - -# Build the unsandboxed main -add_executable(lodepng_unsandboxed - main_unsandboxed.cc - helpers.cc -) - -target_link_libraries(lodepng_unsandboxed PRIVATE - lodepng - sapi::sapi - sapi::temp_file - sapi::file_base - sapi::fileops - glog::glog -) - -# Build the sandboxed main -add_executable(lodepng_sandboxed - main_sandboxed.cc - sandbox.h - helpers.cc -) - -target_link_libraries(lodepng_sandboxed PRIVATE - lodepng_sapi - sapi::sapi - sapi::temp_file - sapi::fileops - sapi::vars - sapi::status - glog::glog -) - -# Build the unit tests -include(GoogleTest) -enable_testing() - -add_executable(main_unit_test - main_unit_test.cc - helpers.cc -) - -target_link_libraries(main_unit_test PRIVATE - lodepng_sapi - absl::memory - absl::strings - absl::time - glog::glog - sapi::flags - sapi::sapi - sapi::temp_file - sapi::fileops - sapi::status - sapi::test_main - sapi::vars -) -gtest_discover_tests(main_unit_test) diff --git a/oss-internship-2020/lodepng/patches/header.patch b/oss-internship-2020/lodepng/patches/header.patch deleted file mode 100644 index dad11dc..0000000 --- a/oss-internship-2020/lodepng/patches/header.patch +++ /dev/null @@ -1,86 +0,0 @@ ---- lodepng.h 2020-09-11 08:41:22.280259945 +0000 -+++ lodepng2.h 2020-09-11 08:45:17.134266042 +0000 -@@ -89,6 +89,8 @@ - #endif - #endif - -+ -+ - #ifdef LODEPNG_COMPILE_CPP - #include - #include -@@ -126,6 +128,9 @@ - bitdepth: the desired bit depth for the raw output image. See explanation on PNG color types. - Return value: LodePNG error code (0 means no error). - */ -+ -+extern "C" { -+ - unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, - const unsigned char* in, size_t insize, - LodePNGColorType colortype, unsigned bitdepth); -@@ -154,10 +159,12 @@ - /*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/ - unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, - const char* filename); -+ - #endif /*LODEPNG_COMPILE_DISK*/ - #endif /*LODEPNG_COMPILE_DECODER*/ - - -+ - #ifdef LODEPNG_COMPILE_ENCODER - /* - Converts raw pixel data into a PNG image in memory. The colortype and bitdepth -@@ -204,6 +211,9 @@ - /*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/ - unsigned lodepng_encode24_file(const char* filename, - const unsigned char* image, unsigned w, unsigned h); -+ -+} -+ - #endif /*LODEPNG_COMPILE_DISK*/ - #endif /*LODEPNG_COMPILE_ENCODER*/ - -@@ -219,6 +229,8 @@ - unsigned decode(std::vector& out, unsigned& w, unsigned& h, - const std::vector& in, - LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); -+ -+ - #ifdef LODEPNG_COMPILE_DISK - /* - Converts PNG file from disk to raw pixel data in memory. -@@ -251,6 +263,7 @@ - unsigned encode(const std::string& filename, - const std::vector& in, unsigned w, unsigned h, - LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); -+ - #endif /* LODEPNG_COMPILE_DISK */ - #endif /* LODEPNG_COMPILE_ENCODER */ - } /* namespace lodepng */ -@@ -318,6 +331,7 @@ - - extern const LodePNGCompressSettings lodepng_default_compress_settings; - void lodepng_compress_settings_init(LodePNGCompressSettings* settings); -+ - #endif /*LODEPNG_COMPILE_ENCODER*/ - - #ifdef LODEPNG_COMPILE_PNG -@@ -943,6 +957,8 @@ - #endif /*LODEPNG_COMPILE_ZLIB*/ - - #ifdef LODEPNG_COMPILE_DISK -+ -+extern "C" { - /* - Load a file from disk into buffer. The function allocates the out buffer, and - after usage you should free it. -@@ -962,6 +978,7 @@ - return value: error code (0 means ok) - */ - unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename); -+} - #endif /*LODEPNG_COMPILE_DISK*/ - - #ifdef LODEPNG_COMPILE_CPP