diff --git a/oss-internship-2020/libtiff/CMakeLists.txt b/oss-internship-2020/libtiff/CMakeLists.txt index 59175d1..7801078 100644 --- a/oss-internship-2020/libtiff/CMakeLists.txt +++ b/oss-internship-2020/libtiff/CMakeLists.txt @@ -22,13 +22,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) # Set this on the command-line set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree") # To obtain a full SAPI_ROOT check out its source separately: -# git clone https://github.com/google/sandboxed-api.git $HOME/sapi_root +# git clone https://github.com/google/sandboxed-api.git /path/to/sapi_root # Then configure: # mkdir -p build && cd build -# cmake .. -G Ninja -DSAPI_ROOT=$HOME/sapi_root +# cmake .. -G Ninja -DSAPI_ROOT=/path/to/sapi_root -option(TIFF_SAPI_ENABLE_EXAMPLES "" ON) -option(TIFF_SAPI_ENABLE_TESTS "" ON) +option(TIFF_SAPI_ENABLE_EXAMPLES "" OFF) +option(TIFF_SAPI_ENABLE_TESTS "" OFF) set(SAPI_ENABLE_EXAMPLES ${TIFF_SAPI_ENABLE_EXAMPLES} CACHE BOOL "" FORCE) set(SAPI_ENABLE_TESTS ${TIFF_SAPI_ENABLE_TESTS} CACHE BOOL "" FORCE) @@ -120,10 +120,10 @@ target_include_directories(tiff_sapi INTERFACE "${PROJECT_BINARY_DIR}" # To find the generated SAPI header ) -#if (TIFF_SAPI_ENABLE_EXAMPLES) +if (TIFF_SAPI_ENABLE_EXAMPLES) add_subdirectory(example) -#endif() +endif() -#if (TIFF_SAPI_ENABLE_TESTS) +if (TIFF_SAPI_ENABLE_TESTS) add_subdirectory(test) -#endif() +endif() diff --git a/oss-internship-2020/libtiff/README.md b/oss-internship-2020/libtiff/README.md index 75ba011..87ac46c 100644 --- a/oss-internship-2020/libtiff/README.md +++ b/oss-internship-2020/libtiff/README.md @@ -9,14 +9,12 @@ You should make sure the libtiff submodule is cloned. ## Usage #### build: -`mkdir -p build && cd build && cmake .. -DSAPI_ROOT=$HOME/sapi_root -DBUILD_SHARED_LIBS=OFF` +`mkdir -p build && cd build && cmake .. -DSAPI_ROOT=/path/to/sapi_root -DBUILD_SHARED_LIBS=OFF` `make -j 8` #### to run the sandboxed example: -`./example/sandboxed absolute/path/to/project/dir` +`./example/sandboxed /absolute/path/to/project/dir` #### to run tests: `./test/tests` - -You also can use sandbox flags `sandbox2_danger_danger_permit_all` and `sandbox2_danger_danger_permit_all_and_log`. diff --git a/oss-internship-2020/libtiff/example/main_sandboxed.cc b/oss-internship-2020/libtiff/example/main_sandboxed.cc index 08a0cc1..c09f7b4 100644 --- a/oss-internship-2020/libtiff/example/main_sandboxed.cc +++ b/oss-internship-2020/libtiff/example/main_sandboxed.cc @@ -23,15 +23,6 @@ #include "sandboxed_api/vars.h" #include "tiffio.h" // NOLINT(build/include) -// sapi functions: -// TIFFTileSize -// TIFFOpen -// TIFFReadEncodedTile -// TIFFSetField -// TIFFClose -// TIFFReadRGBATile -// TIFFGetField - constexpr std::array kCluster0 = {0, 0, 2, 0, 138, 139}; constexpr std::array kCluster64 = {0, 0, 9, 6, 134, 119}; constexpr std::array kCluster128 = {44, 40, 63, 59, 230, 95}; diff --git a/oss-internship-2020/libtiff/test/check_tag.cc b/oss-internship-2020/libtiff/test/check_tag.cc index 0f48835..99159b8 100644 --- a/oss-internship-2020/libtiff/test/check_tag.cc +++ b/oss-internship-2020/libtiff/test/check_tag.cc @@ -14,9 +14,6 @@ #include "check_tag.h" -// sapi functions: -// TIFFGetField - void CheckShortField(TiffApi& api, sapi::v::RemotePtr& tif, const ttag_t field, const uint16_t value) { sapi::v::UShort tmp(123); diff --git a/oss-internship-2020/libtiff/test/defer_strile_writing.cc b/oss-internship-2020/libtiff/test/defer_strile_writing.cc index f7da76f..5162d6f 100644 --- a/oss-internship-2020/libtiff/test/defer_strile_writing.cc +++ b/oss-internship-2020/libtiff/test/defer_strile_writing.cc @@ -17,24 +17,6 @@ #include "helper.h" #include "tiffio.h" // NOLINT(build/include) -// sapi functions: -// TIFFOpen -// TIFFClose -// TIFFGetField -// TIFFSetField -// TIFFWriteCheck -// TIFFSetDirectory -// TIFFFreeDirectory -// TIFFWriteScanline -// TIFFWriteDirectory -// TIFFCreateDirectory -// TIFFReadEncodedTile -// TIFFReadEncodedStrip -// TIFFWriteEncodedTile -// TIFFWriteEncodedStrip -// TIFFDeferStrileArrayWriting -// TIFFForceStrileArrayWriting - namespace { #define TBS 256 // kTileBufferSize diff --git a/oss-internship-2020/libtiff/test/long_tag.cc b/oss-internship-2020/libtiff/test/long_tag.cc index bc1b62a..175bd82 100644 --- a/oss-internship-2020/libtiff/test/long_tag.cc +++ b/oss-internship-2020/libtiff/test/long_tag.cc @@ -17,13 +17,6 @@ #include "check_tag.h" #include "tiffio.h" // NOLINT(build/include) -// sapi functions: -// TIFFWriteScanline -// TIFFOpen -// TIFFClose -// TIFFGetField (from check_tag.c) -// TIFFSetField - namespace { struct LongTag { diff --git a/oss-internship-2020/libtiff/test/raw_decode.cc b/oss-internship-2020/libtiff/test/raw_decode.cc index 9d9b311..5193dd2 100644 --- a/oss-internship-2020/libtiff/test/raw_decode.cc +++ b/oss-internship-2020/libtiff/test/raw_decode.cc @@ -19,23 +19,17 @@ #include "helper.h" #include "tiffio.h" // NOLINT(build/include) -// sapi functions: -// TIFFOpen -// TIFFClose -// TIFFGetField -// TIFFSetField -// TIFFTileSize -// TIFFReadRGBATile -// TIFFReadEncodedTile - namespace { constexpr std::array kCluster0 = {0, 0, 2, 0, 138, 139}; constexpr std::array kCluster64 = {0, 0, 9, 6, 134, 119}; constexpr std::array kCluster128 = {44, 40, 63, 59, 230, 95}; -int CheckCluster(int cluster, const sapi::v::Array& buffer, +constexpr unsigned kRawTileNumber = 9; + +bool CheckCluster(int cluster, const sapi::v::Array& buffer, const std::array& expected_cluster) { + ASSERT_THAT(buffer.GetSize() > 3 * pixel, IsTrue()); uint8_t* target = buffer.GetData() + cluster * 6; bool comp = !(std::memcmp(target, expected_cluster.data(), 6) == 0); @@ -43,17 +37,18 @@ int CheckCluster(int cluster, const sapi::v::Array& buffer, EXPECT_THAT(comp, IsFalse()) << "Cluster " << cluster << " did not match expected results.\n" << "Expect: " << expected_cluster[0] << "\t" << expected_cluster[1] - << "\t" << expected_cluster[4] << "\t" << expected_cluster[5] << "\t" - << expected_cluster[2] << "\t" << expected_cluster[3] << "\n" - << "Got: " << target[0] << "\t" << target[1] << "\t" << target[4] << "\t" - << target[5] << "\t" << target[2] << "\t" << target[3]; + << "\t" << expected_cluster[2] << "\t" << expected_cluster[3] << "\t" + << expected_cluster[4] << "\t" << expected_cluster[5] << "\n" + << "Got: " << target[0] << "\t" << target[1] << "\t" << target[2] << "\t" + << target[3] << "\t" << target[4] << "\t" << target[4]; return comp; } -int CheckRgbPixel(int pixel, int min_red, int max_red, int min_green, +bool CheckRgbPixel(int pixel, int min_red, int max_red, int min_green, int max_green, int min_blue, int max_blue, const sapi::v::Array& buffer) { + ASSERT_THAT(buffer.GetSize() > 3 * pixel, IsTrue()); uint8_t* rgb = buffer.GetData() + 3 * pixel; bool comp = @@ -69,11 +64,13 @@ int CheckRgbPixel(int pixel, int min_red, int max_red, int min_green, return comp; } -int CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green, +bool CheckRgbaPixel(int pixel, int min_red, int max_red, int min_green, int max_green, int min_blue, int max_blue, int min_alpha, int max_alpha, const sapi::v::Array& buffer) { // RGBA images are upside down - adjust for normal ordering int adjusted_pixel = pixel % 128 + (127 - (pixel / 128)) * 128; + + ASSERT_THAT(buffer.GetSize() > adjusted_pixel, IsTrue()); unsigned rgba = buffer[adjusted_pixel]; bool comp = !(TIFFGetR(rgba) >= (unsigned)min_red && @@ -102,7 +99,7 @@ TEST(SandboxTest, RawDecode) { ASSERT_THAT(sandbox.Init(), IsOk()) << "Couldn't initialize Sandboxed API"; tsize_t sz; - unsigned int pixel_status = 0; + bool pixel_status = false; sapi::v::UShort h, v; sapi::StatusOr status_or_tif; sapi::StatusOr status_or_int; @@ -134,7 +131,8 @@ TEST(SandboxTest, RawDecode) { sz = status_or_long.value(); sapi::v::Array buffer_(sz); - status_or_long = api.TIFFReadEncodedTile(&tif, 9, buffer_.PtrBoth(), sz); + // Read a tile in decompressed form, but still YCbCr subsampled + status_or_long = api.TIFFReadEncodedTile(&tif, kRawTileNumber, buffer_.PtrBoth(), sz); ASSERT_THAT(status_or_long, IsOk()) << "TIFFReadEncodedTile fatal error"; EXPECT_THAT(status_or_long.value(), Eq(sz)) << "Did not get expected result code from TIFFReadEncodedTile()(" @@ -158,7 +156,7 @@ TEST(SandboxTest, RawDecode) { sz = status_or_long.value(); sapi::v::Array buffer2_(sz); - status_or_long = api.TIFFReadEncodedTile(&tif, 9, buffer2_.PtrBoth(), sz); + status_or_long = api.TIFFReadEncodedTile(&tif, kRawTileNumber, buffer2_.PtrBoth(), sz); ASSERT_THAT(status_or_long, IsOk()) << "TIFFReadEncodedTile fatal error"; EXPECT_THAT(status_or_long.value(), Eq(sz)) << "Did not get expected result code from TIFFReadEncodedTile()(" diff --git a/oss-internship-2020/libtiff/test/short_tag.cc b/oss-internship-2020/libtiff/test/short_tag.cc index 8d0d011..29ccac9 100644 --- a/oss-internship-2020/libtiff/test/short_tag.cc +++ b/oss-internship-2020/libtiff/test/short_tag.cc @@ -18,13 +18,6 @@ #include "check_tag.h" #include "tiffio.h" // NOLINT(build/include) -// sapi functions: -// TIFFWriteScanline -// TIFFOpen -// TIFFClose -// TIFFGetField (from check_tag.c) -// TIFFSetField - namespace { #define SPP 3 // kSamplePerPixel