mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
resolved part of issues
This commit is contained in:
parent
8b36b3e5af
commit
d513f18c2e
|
@ -22,13 +22,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
# Set this on the command-line
|
# Set this on the command-line
|
||||||
set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree")
|
set(SAPI_ROOT "" CACHE PATH "Path to the Sandboxed API source tree")
|
||||||
# To obtain a full SAPI_ROOT check out its source separately:
|
# 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:
|
# Then configure:
|
||||||
# mkdir -p build && cd build
|
# 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_EXAMPLES "" OFF)
|
||||||
option(TIFF_SAPI_ENABLE_TESTS "" ON)
|
option(TIFF_SAPI_ENABLE_TESTS "" OFF)
|
||||||
|
|
||||||
set(SAPI_ENABLE_EXAMPLES ${TIFF_SAPI_ENABLE_EXAMPLES} CACHE BOOL "" FORCE)
|
set(SAPI_ENABLE_EXAMPLES ${TIFF_SAPI_ENABLE_EXAMPLES} CACHE BOOL "" FORCE)
|
||||||
set(SAPI_ENABLE_TESTS ${TIFF_SAPI_ENABLE_TESTS} 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
|
"${PROJECT_BINARY_DIR}" # To find the generated SAPI header
|
||||||
)
|
)
|
||||||
|
|
||||||
#if (TIFF_SAPI_ENABLE_EXAMPLES)
|
if (TIFF_SAPI_ENABLE_EXAMPLES)
|
||||||
add_subdirectory(example)
|
add_subdirectory(example)
|
||||||
#endif()
|
endif()
|
||||||
|
|
||||||
#if (TIFF_SAPI_ENABLE_TESTS)
|
if (TIFF_SAPI_ENABLE_TESTS)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
#endif()
|
endif()
|
||||||
|
|
|
@ -9,14 +9,12 @@ You should make sure the libtiff submodule is cloned.
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
#### build:
|
#### 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`
|
`make -j 8`
|
||||||
|
|
||||||
#### to run the sandboxed example:
|
#### to run the sandboxed example:
|
||||||
`./example/sandboxed absolute/path/to/project/dir`
|
`./example/sandboxed /absolute/path/to/project/dir`
|
||||||
|
|
||||||
#### to run tests:
|
#### to run tests:
|
||||||
`./test/tests`
|
`./test/tests`
|
||||||
|
|
||||||
You also can use sandbox flags `sandbox2_danger_danger_permit_all` and `sandbox2_danger_danger_permit_all_and_log`.
|
|
||||||
|
|
|
@ -23,15 +23,6 @@
|
||||||
#include "sandboxed_api/vars.h"
|
#include "sandboxed_api/vars.h"
|
||||||
#include "tiffio.h" // NOLINT(build/include)
|
#include "tiffio.h" // NOLINT(build/include)
|
||||||
|
|
||||||
// sapi functions:
|
|
||||||
// TIFFTileSize
|
|
||||||
// TIFFOpen
|
|
||||||
// TIFFReadEncodedTile
|
|
||||||
// TIFFSetField
|
|
||||||
// TIFFClose
|
|
||||||
// TIFFReadRGBATile
|
|
||||||
// TIFFGetField
|
|
||||||
|
|
||||||
constexpr std::array<uint8_t, 6> kCluster0 = {0, 0, 2, 0, 138, 139};
|
constexpr std::array<uint8_t, 6> kCluster0 = {0, 0, 2, 0, 138, 139};
|
||||||
constexpr std::array<uint8_t, 6> kCluster64 = {0, 0, 9, 6, 134, 119};
|
constexpr std::array<uint8_t, 6> kCluster64 = {0, 0, 9, 6, 134, 119};
|
||||||
constexpr std::array<uint8_t, 6> kCluster128 = {44, 40, 63, 59, 230, 95};
|
constexpr std::array<uint8_t, 6> kCluster128 = {44, 40, 63, 59, 230, 95};
|
||||||
|
|
|
@ -14,9 +14,6 @@
|
||||||
|
|
||||||
#include "check_tag.h"
|
#include "check_tag.h"
|
||||||
|
|
||||||
// sapi functions:
|
|
||||||
// TIFFGetField
|
|
||||||
|
|
||||||
void CheckShortField(TiffApi& api, sapi::v::RemotePtr& tif, const ttag_t field,
|
void CheckShortField(TiffApi& api, sapi::v::RemotePtr& tif, const ttag_t field,
|
||||||
const uint16_t value) {
|
const uint16_t value) {
|
||||||
sapi::v::UShort tmp(123);
|
sapi::v::UShort tmp(123);
|
||||||
|
|
|
@ -17,24 +17,6 @@
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
#include "tiffio.h" // NOLINT(build/include)
|
#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 {
|
namespace {
|
||||||
|
|
||||||
#define TBS 256 // kTileBufferSize
|
#define TBS 256 // kTileBufferSize
|
||||||
|
|
|
@ -17,13 +17,6 @@
|
||||||
#include "check_tag.h"
|
#include "check_tag.h"
|
||||||
#include "tiffio.h" // NOLINT(build/include)
|
#include "tiffio.h" // NOLINT(build/include)
|
||||||
|
|
||||||
// sapi functions:
|
|
||||||
// TIFFWriteScanline
|
|
||||||
// TIFFOpen
|
|
||||||
// TIFFClose
|
|
||||||
// TIFFGetField (from check_tag.c)
|
|
||||||
// TIFFSetField
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct LongTag {
|
struct LongTag {
|
||||||
|
|
|
@ -19,23 +19,17 @@
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
#include "tiffio.h" // NOLINT(build/include)
|
#include "tiffio.h" // NOLINT(build/include)
|
||||||
|
|
||||||
// sapi functions:
|
|
||||||
// TIFFOpen
|
|
||||||
// TIFFClose
|
|
||||||
// TIFFGetField
|
|
||||||
// TIFFSetField
|
|
||||||
// TIFFTileSize
|
|
||||||
// TIFFReadRGBATile
|
|
||||||
// TIFFReadEncodedTile
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr std::array<uint8_t, 6> kCluster0 = {0, 0, 2, 0, 138, 139};
|
constexpr std::array<uint8_t, 6> kCluster0 = {0, 0, 2, 0, 138, 139};
|
||||||
constexpr std::array<uint8_t, 6> kCluster64 = {0, 0, 9, 6, 134, 119};
|
constexpr std::array<uint8_t, 6> kCluster64 = {0, 0, 9, 6, 134, 119};
|
||||||
constexpr std::array<uint8_t, 6> kCluster128 = {44, 40, 63, 59, 230, 95};
|
constexpr std::array<uint8_t, 6> kCluster128 = {44, 40, 63, 59, 230, 95};
|
||||||
|
|
||||||
int CheckCluster(int cluster, const sapi::v::Array<uint8_t>& buffer,
|
constexpr unsigned kRawTileNumber = 9;
|
||||||
|
|
||||||
|
bool CheckCluster(int cluster, const sapi::v::Array<uint8_t>& buffer,
|
||||||
const std::array<uint8_t, 6>& expected_cluster) {
|
const std::array<uint8_t, 6>& expected_cluster) {
|
||||||
|
ASSERT_THAT(buffer.GetSize() > 3 * pixel, IsTrue());
|
||||||
uint8_t* target = buffer.GetData() + cluster * 6;
|
uint8_t* target = buffer.GetData() + cluster * 6;
|
||||||
|
|
||||||
bool comp = !(std::memcmp(target, expected_cluster.data(), 6) == 0);
|
bool comp = !(std::memcmp(target, expected_cluster.data(), 6) == 0);
|
||||||
|
@ -43,17 +37,18 @@ int CheckCluster(int cluster, const sapi::v::Array<uint8_t>& buffer,
|
||||||
EXPECT_THAT(comp, IsFalse())
|
EXPECT_THAT(comp, IsFalse())
|
||||||
<< "Cluster " << cluster << " did not match expected results.\n"
|
<< "Cluster " << cluster << " did not match expected results.\n"
|
||||||
<< "Expect: " << expected_cluster[0] << "\t" << expected_cluster[1]
|
<< "Expect: " << expected_cluster[0] << "\t" << expected_cluster[1]
|
||||||
<< "\t" << expected_cluster[4] << "\t" << expected_cluster[5] << "\t"
|
<< "\t" << expected_cluster[2] << "\t" << expected_cluster[3] << "\t"
|
||||||
<< expected_cluster[2] << "\t" << expected_cluster[3] << "\n"
|
<< expected_cluster[4] << "\t" << expected_cluster[5] << "\n"
|
||||||
<< "Got: " << target[0] << "\t" << target[1] << "\t" << target[4] << "\t"
|
<< "Got: " << target[0] << "\t" << target[1] << "\t" << target[2] << "\t"
|
||||||
<< target[5] << "\t" << target[2] << "\t" << target[3];
|
<< target[3] << "\t" << target[4] << "\t" << target[4];
|
||||||
|
|
||||||
return comp;
|
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,
|
int max_green, int min_blue, int max_blue,
|
||||||
const sapi::v::Array<uint8_t>& buffer) {
|
const sapi::v::Array<uint8_t>& buffer) {
|
||||||
|
ASSERT_THAT(buffer.GetSize() > 3 * pixel, IsTrue());
|
||||||
uint8_t* rgb = buffer.GetData() + 3 * pixel;
|
uint8_t* rgb = buffer.GetData() + 3 * pixel;
|
||||||
|
|
||||||
bool comp =
|
bool comp =
|
||||||
|
@ -69,11 +64,13 @@ int CheckRgbPixel(int pixel, int min_red, int max_red, int min_green,
|
||||||
return comp;
|
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_green, int min_blue, int max_blue, int min_alpha,
|
||||||
int max_alpha, const sapi::v::Array<unsigned>& buffer) {
|
int max_alpha, const sapi::v::Array<unsigned>& buffer) {
|
||||||
// RGBA images are upside down - adjust for normal ordering
|
// RGBA images are upside down - adjust for normal ordering
|
||||||
int adjusted_pixel = pixel % 128 + (127 - (pixel / 128)) * 128;
|
int adjusted_pixel = pixel % 128 + (127 - (pixel / 128)) * 128;
|
||||||
|
|
||||||
|
ASSERT_THAT(buffer.GetSize() > adjusted_pixel, IsTrue());
|
||||||
unsigned rgba = buffer[adjusted_pixel];
|
unsigned rgba = buffer[adjusted_pixel];
|
||||||
|
|
||||||
bool comp = !(TIFFGetR(rgba) >= (unsigned)min_red &&
|
bool comp = !(TIFFGetR(rgba) >= (unsigned)min_red &&
|
||||||
|
@ -102,7 +99,7 @@ TEST(SandboxTest, RawDecode) {
|
||||||
ASSERT_THAT(sandbox.Init(), IsOk()) << "Couldn't initialize Sandboxed API";
|
ASSERT_THAT(sandbox.Init(), IsOk()) << "Couldn't initialize Sandboxed API";
|
||||||
|
|
||||||
tsize_t sz;
|
tsize_t sz;
|
||||||
unsigned int pixel_status = 0;
|
bool pixel_status = false;
|
||||||
sapi::v::UShort h, v;
|
sapi::v::UShort h, v;
|
||||||
sapi::StatusOr<TIFF*> status_or_tif;
|
sapi::StatusOr<TIFF*> status_or_tif;
|
||||||
sapi::StatusOr<int> status_or_int;
|
sapi::StatusOr<int> status_or_int;
|
||||||
|
@ -134,7 +131,8 @@ TEST(SandboxTest, RawDecode) {
|
||||||
sz = status_or_long.value();
|
sz = status_or_long.value();
|
||||||
|
|
||||||
sapi::v::Array<uint8_t> buffer_(sz);
|
sapi::v::Array<uint8_t> 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";
|
ASSERT_THAT(status_or_long, IsOk()) << "TIFFReadEncodedTile fatal error";
|
||||||
EXPECT_THAT(status_or_long.value(), Eq(sz))
|
EXPECT_THAT(status_or_long.value(), Eq(sz))
|
||||||
<< "Did not get expected result code from TIFFReadEncodedTile()("
|
<< "Did not get expected result code from TIFFReadEncodedTile()("
|
||||||
|
@ -158,7 +156,7 @@ TEST(SandboxTest, RawDecode) {
|
||||||
sz = status_or_long.value();
|
sz = status_or_long.value();
|
||||||
|
|
||||||
sapi::v::Array<uint8_t> buffer2_(sz);
|
sapi::v::Array<uint8_t> 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";
|
ASSERT_THAT(status_or_long, IsOk()) << "TIFFReadEncodedTile fatal error";
|
||||||
EXPECT_THAT(status_or_long.value(), Eq(sz))
|
EXPECT_THAT(status_or_long.value(), Eq(sz))
|
||||||
<< "Did not get expected result code from TIFFReadEncodedTile()("
|
<< "Did not get expected result code from TIFFReadEncodedTile()("
|
||||||
|
|
|
@ -18,13 +18,6 @@
|
||||||
#include "check_tag.h"
|
#include "check_tag.h"
|
||||||
#include "tiffio.h" // NOLINT(build/include)
|
#include "tiffio.h" // NOLINT(build/include)
|
||||||
|
|
||||||
// sapi functions:
|
|
||||||
// TIFFWriteScanline
|
|
||||||
// TIFFOpen
|
|
||||||
// TIFFClose
|
|
||||||
// TIFFGetField (from check_tag.c)
|
|
||||||
// TIFFSetField
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
#define SPP 3 // kSamplePerPixel
|
#define SPP 3 // kSamplePerPixel
|
||||||
|
|
Loading…
Reference in New Issue
Block a user