diff --git a/oss-internship-2020/guetzli/README.md b/oss-internship-2020/guetzli/README.md index 042f165..97b3bc3 100644 --- a/oss-internship-2020/guetzli/README.md +++ b/oss-internship-2020/guetzli/README.md @@ -25,5 +25,8 @@ There are two different sets of unit tests which demonstrate how to use differen * `tests/guetzli_sapi_test.cc` - example usage of Guetzli sandboxed API. * `tests/guetzli_transaction_test.cc` - example usage of Guetzli transaction. +To run tests use following command: +`bazel test ...` + Also, there is an example of custom security policy for your sandbox in `guetzli_sandbox.h` diff --git a/oss-internship-2020/guetzli/guetzli_entry_points.cc b/oss-internship-2020/guetzli/guetzli_entry_points.cc index a36431b..7368928 100644 --- a/oss-internship-2020/guetzli/guetzli_entry_points.cc +++ b/oss-internship-2020/guetzli/guetzli_entry_points.cc @@ -154,7 +154,7 @@ sapi::StatusOr ReadPNG(const std::string& data) { xsize = png_get_image_width(png_ptr, info_ptr); ysize = png_get_image_height(png_ptr, info_ptr); - rgb.resize(3 * (xsize) * (ysize)); + rgb.resize(3 * xsize * ysize); const int components = png_get_channels(png_ptr, info_ptr); switch (components) { @@ -162,7 +162,7 @@ sapi::StatusOr ReadPNG(const std::string& data) { // GRAYSCALE for (int y = 0; y < ysize; ++y) { const uint8_t* row_in = row_pointers[y]; - uint8_t* row_out = &(rgb)[3 * y * (xsize)]; + uint8_t* row_out = &rgb[3 * y * xsize]; for (int x = 0; x < xsize; ++x) { const uint8_t gray = row_in[x]; row_out[3 * x + 0] = gray; @@ -176,7 +176,7 @@ sapi::StatusOr ReadPNG(const std::string& data) { // GRAYSCALE + ALPHA for (int y = 0; y < ysize; ++y) { const uint8_t* row_in = row_pointers[y]; - uint8_t* row_out = &(rgb)[3 * y * (xsize)]; + uint8_t* row_out = &rgb[3 * y * xsize]; for (int x = 0; x < xsize; ++x) { const uint8_t gray = BlendOnBlack(row_in[2 * x], row_in[2 * x + 1]); row_out[3 * x + 0] = gray; @@ -190,8 +190,8 @@ sapi::StatusOr ReadPNG(const std::string& data) { // RGB for (int y = 0; y < ysize; ++y) { const uint8_t* row_in = row_pointers[y]; - uint8_t* row_out = &(rgb)[3 * y * (xsize)]; - memcpy(row_out, row_in, 3 * (xsize)); + uint8_t* row_out = &rgb[3 * y * xsize]; + memcpy(row_out, row_in, 3 * xsize); } break; } @@ -199,7 +199,7 @@ sapi::StatusOr ReadPNG(const std::string& data) { // RGBA for (int y = 0; y < ysize; ++y) { const uint8_t* row_in = row_pointers[y]; - uint8_t* row_out = &(rgb)[3 * y * (xsize)]; + uint8_t* row_out = &rgb[3 * y * xsize]; for (int x = 0; x < xsize; ++x) { const uint8_t alpha = row_in[4 * x + 3]; row_out[3 * x + 0] = BlendOnBlack(row_in[4 * x + 0], alpha); diff --git a/oss-internship-2020/guetzli/guetzli_transaction.cc b/oss-internship-2020/guetzli/guetzli_transaction.cc index 64fac51..8fd1db4 100644 --- a/oss-internship-2020/guetzli/guetzli_transaction.cc +++ b/oss-internship-2020/guetzli/guetzli_transaction.cc @@ -107,6 +107,7 @@ absl::Status GuetzliTransaction::LinkOutFile(int out_fd) const { std::stringstream path; path << "/proc/self/fd/" << out_fd; + if (linkat(AT_FDCWD, path.str().c_str(), AT_FDCWD, params_.out_file, AT_SYMLINK_FOLLOW) < 0) { std::stringstream error; diff --git a/oss-internship-2020/guetzli/guetzli_transaction.h b/oss-internship-2020/guetzli/guetzli_transaction.h index 1a7c7d3..c9c0d7d 100644 --- a/oss-internship-2020/guetzli/guetzli_transaction.h +++ b/oss-internship-2020/guetzli/guetzli_transaction.h @@ -42,12 +42,11 @@ struct TransactionParams { // Create a new one for each processing operation class GuetzliTransaction : public sapi::Transaction { public: - GuetzliTransaction(TransactionParams params) + GuetzliTransaction(TransactionParams params, int retry_count = 0) : sapi::Transaction(std::make_unique()) , params_(std::move(params)) { - //TODO: Add retry count as a parameter - sapi::Transaction::set_retry_count(kDefaultTransactionRetryCount); + sapi::Transaction::set_retry_count(retry_count); sapi::Transaction::SetTimeLimit(0); // Infinite time limit } @@ -59,8 +58,6 @@ class GuetzliTransaction : public sapi::Transaction { const TransactionParams params_; ImageType image_type_ = ImageType::kJpeg; - - static const int kDefaultTransactionRetryCount = 0; }; } // namespace sandbox