use &sapi:✌️:NullPtr instead of sapi:✌️:NullPtr().PthBoth() as NULL inside the sandbox; remove unused wrapper for png_write_end

This commit is contained in:
Alexandra Latysheva 2020-10-30 11:17:45 +00:00
parent bcecc9e74a
commit 7b6b2d2fe8
6 changed files with 21 additions and 36 deletions

View File

@ -14,7 +14,7 @@
#include <string>
#include "../sandboxed.h" // NOLINT(build/include)
#include "../sandboxed.h" // NOLINT(build/include)
#include "../tests/libpng.h" // NOLINT(build/include)
#include "sandboxed_api/vars.h"
@ -51,19 +51,18 @@ absl::Status LibPNGMain(const std::string& infile, const std::string& outfile) {
free(buffer);
sapi::v::Array<uint8_t> buffer_(PNG_IMAGE_SIZE(*image.mutable_data()));
SAPI_ASSIGN_OR_RETURN(
result, api.png_image_finish_read(
image.PtrBoth(), sapi::v::NullPtr().PtrBoth(),
buffer_.PtrBoth(), 0, sapi::v::NullPtr().PtrBoth()));
sapi::v::NullPtr null = sapi::v::NullPtr();
SAPI_ASSIGN_OR_RETURN(result,
api.png_image_finish_read(image.PtrBoth(), &null,
buffer_.PtrBoth(), 0, &null));
if (!result) {
return absl::InternalError(
absl::StrCat("finish read error: ", image.mutable_data()->message));
}
SAPI_ASSIGN_OR_RETURN(
result, api.png_image_write_to_file(
image.PtrBoth(), outfile_var.PtrBefore(), 0,
buffer_.PtrBoth(), 0, sapi::v::NullPtr().PtrBoth()));
SAPI_ASSIGN_OR_RETURN(result, api.png_image_write_to_file(
image.PtrBoth(), outfile_var.PtrBefore(), 0,
buffer_.PtrBoth(), 0, &null));
if (!result) {
return absl::InternalError(
absl::StrCat("write error: ", image.mutable_data()->message));
@ -87,4 +86,3 @@ int main(int argc, const char** argv) {
return EXIT_SUCCESS;
}

View File

@ -15,7 +15,7 @@
#include <fcntl.h>
#include <unistd.h>
#include "../sandboxed.h" // NOLINT(build/include)
#include "../sandboxed.h" // NOLINT(build/include)
#include "../tests/libpng.h" // NOLINT(build/include)
struct Data {
@ -65,10 +65,10 @@ absl::Status ReadPng(LibPNGApi& api, LibPNGSapiSandbox& sandbox,
absl::StatusOr<png_structp> status_or_png_structp;
sapi::v::ConstCStr ver_string_var(PNG_LIBPNG_VER_STRING);
sapi::v::NullPtr null = sapi::v::NullPtr();
SAPI_ASSIGN_OR_RETURN(
status_or_png_structp,
api.png_create_read_struct_wrapper(ver_string_var.PtrBefore(),
sapi::v::NullPtr().PtrBoth()));
api.png_create_read_struct_wrapper(ver_string_var.PtrBefore(), &null));
sapi::v::RemotePtr struct_ptr(status_or_png_structp.value());
if (!struct_ptr.GetValue()) {
@ -143,10 +143,10 @@ absl::Status WritePng(LibPNGApi& api, LibPNGSapiSandbox& sandbox,
absl::StatusOr<png_structp> status_or_png_structp;
sapi::v::ConstCStr ver_string_var(PNG_LIBPNG_VER_STRING);
sapi::v::NullPtr null = sapi::v::NullPtr();
SAPI_ASSIGN_OR_RETURN(
status_or_png_structp,
api.png_create_write_struct_wrapper(ver_string_var.PtrBefore(),
sapi::v::NullPtr().PtrBoth()));
api.png_create_write_struct_wrapper(ver_string_var.PtrBefore(), &null));
sapi::v::RemotePtr struct_ptr(status_or_png_structp.value());
if (!struct_ptr.GetValue()) {
@ -176,7 +176,6 @@ absl::Status WritePng(LibPNGApi& api, LibPNGSapiSandbox& sandbox,
SAPI_RETURN_IF_ERROR(api.png_write_image_wrapper(
&struct_ptr, d.row_pointers->PtrBefore(), d.height, d.rowbytes));
auto null = sapi::v::NullPtr();
SAPI_RETURN_IF_ERROR(api.png_setjmp(&struct_ptr));
SAPI_RETURN_IF_ERROR(api.png_write_end(&struct_ptr, &null));
@ -236,4 +235,3 @@ int main(int argc, const char** argv) {
return EXIT_SUCCESS;
}

View File

@ -64,9 +64,9 @@ TEST(SandboxTest, ReadWrite) {
<< "image version changed";
sapi::v::Array<uint8_t> buffer_(PNG_IMAGE_SIZE(*image.mutable_data()));
status_or_int = api.png_image_finish_read(
image.PtrBoth(), sapi::v::NullPtr().PtrBoth(), buffer_.PtrBoth(), 0,
sapi::v::NullPtr().PtrBoth());
sapi::v::NullPtr null = sapi::v::NullPtr();
status_or_int = api.png_image_finish_read(image.PtrBoth(), &null,
buffer_.PtrBoth(), 0, &null);
ASSERT_THAT(status_or_int, IsOk()) << "png_image_finish_read fatal error";
ASSERT_THAT(status_or_int.value(), IsTrue())
<< "png_image_finish_read failed: " << image.mutable_data()->message;
@ -76,8 +76,7 @@ TEST(SandboxTest, ReadWrite) {
<< "image format changed";
status_or_int = api.png_image_write_to_file(
image.PtrBoth(), outfile_var.PtrBefore(), 0, buffer_.PtrBoth(), 0,
sapi::v::NullPtr().PtrBoth());
image.PtrBoth(), outfile_var.PtrBefore(), 0, buffer_.PtrBoth(), 0, &null);
ASSERT_THAT(status_or_int, IsOk()) << "png_image_write_to_file fatal error";
ASSERT_THAT(status_or_int.value(), IsTrue())
<< "png_image_finish_read failed: " << image.mutable_data()->message;
@ -88,4 +87,3 @@ TEST(SandboxTest, ReadWrite) {
}
} // namespace

View File

@ -69,9 +69,9 @@ void ReadPng(LibPNGApi& api, LibPNGSapiSandbox& sandbox,
ASSERT_THAT(status_or_int.value(), Eq(0)) << infile << " is not a PNG file";
sapi::v::ConstCStr ver_string_var(PNG_LIBPNG_VER_STRING);
sapi::v::NullPtr null = sapi::v::NullPtr();
absl::StatusOr<png_structp> status_or_png_structp =
api.png_create_read_struct_wrapper(ver_string_var.PtrBefore(),
sapi::v::NullPtr().PtrBoth());
api.png_create_read_struct_wrapper(ver_string_var.PtrBefore(), &null);
ASSERT_THAT(status_or_png_structp, IsOk());
sapi::v::RemotePtr struct_ptr(status_or_png_structp.value());
@ -151,9 +151,9 @@ void WritePng(LibPNGApi& api, LibPNGSapiSandbox& sandbox,
ASSERT_THAT(file.GetValue(), NotNull()) << "Could not open " << outfile;
sapi::v::ConstCStr ver_string_var(PNG_LIBPNG_VER_STRING);
sapi::v::NullPtr null = sapi::v::NullPtr();
absl::StatusOr<png_structp> status_or_png_structp =
api.png_create_write_struct_wrapper(ver_string_var.PtrBefore(),
sapi::v::NullPtr().PtrBoth());
api.png_create_write_struct_wrapper(ver_string_var.PtrBefore(), &null);
ASSERT_THAT(status_or_png_structp, IsOk());
sapi::v::RemotePtr struct_ptr(status_or_png_structp.value());
@ -186,7 +186,6 @@ void WritePng(LibPNGApi& api, LibPNGSapiSandbox& sandbox,
data.height, data.rowbytes),
IsOk());
auto null = sapi::v::NullPtr();
ASSERT_THAT(api.png_setjmp(&struct_ptr), IsOk());
ASSERT_THAT(api.png_write_end(&struct_ptr, &null), IsOk());
@ -245,4 +244,3 @@ TEST(SandboxTest, ReadModifyWrite) {
}
} // namespace

View File

@ -50,8 +50,3 @@ void png_write_image_wrapper(png_structrp png_ptr, png_bytep image,
png_write_image(png_ptr, ptrs);
free(ptrs);
}
void png_write_end_wrapper(png_structrp png_ptr) {
png_write_end(png_ptr, NULL);
}

View File

@ -18,7 +18,5 @@ void png_read_image_wrapper(png_structrp png_ptr, png_bytep image,
size_t height, size_t rowbytes);
void png_write_image_wrapper(png_structrp png_ptr, png_bytep image,
size_t height, size_t rowbytes);
void png_write_end_wrapper(png_structrp png_ptr);
}
#endif