Reject non-finite PPI layer opacity
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <bit>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
@@ -43,6 +44,19 @@ void append_f32(std::vector<std::byte>& bytes, float value)
|
||||
append_u32(bytes, std::bit_cast<std::uint32_t>(value));
|
||||
}
|
||||
|
||||
void write_u32_at(std::vector<std::byte>& bytes, std::size_t offset, std::uint32_t value)
|
||||
{
|
||||
bytes[offset + 0U] = static_cast<std::byte>(value & 0xffU);
|
||||
bytes[offset + 1U] = static_cast<std::byte>((value >> 8U) & 0xffU);
|
||||
bytes[offset + 2U] = static_cast<std::byte>((value >> 16U) & 0xffU);
|
||||
bytes[offset + 3U] = static_cast<std::byte>((value >> 24U) & 0xffU);
|
||||
}
|
||||
|
||||
void write_f32_at(std::vector<std::byte>& bytes, std::size_t offset, float value)
|
||||
{
|
||||
write_u32_at(bytes, offset, std::bit_cast<std::uint32_t>(value));
|
||||
}
|
||||
|
||||
void append_ascii(std::vector<std::byte>& bytes, std::string_view value)
|
||||
{
|
||||
for (const auto ch : value) {
|
||||
@@ -375,9 +389,16 @@ void rejects_invalid_project_body_summaries(pp::tests::Harness& h)
|
||||
auto bad_layer_name = minimal_project();
|
||||
bad_layer_name[ppi_header_size + (128U * 128U * 4U) + 24U] = std::byte { 255 };
|
||||
|
||||
auto non_finite_opacity = minimal_project();
|
||||
write_f32_at(
|
||||
non_finite_opacity,
|
||||
ppi_header_size + (128U * 128U * 4U) + 20U,
|
||||
std::numeric_limits<float>::quiet_NaN());
|
||||
|
||||
const auto truncated_result = parse_ppi_project_summary(truncated);
|
||||
const auto mismatched_frames_result = parse_ppi_project_summary(mismatched_frames);
|
||||
const auto bad_layer_name_result = parse_ppi_project_summary(bad_layer_name);
|
||||
const auto non_finite_opacity_result = parse_ppi_project_summary(non_finite_opacity);
|
||||
|
||||
PP_EXPECT(h, !truncated_result.ok());
|
||||
PP_EXPECT(h, truncated_result.status().code == StatusCode::out_of_range);
|
||||
@@ -385,6 +406,8 @@ void rejects_invalid_project_body_summaries(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, mismatched_frames_result.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !bad_layer_name_result.ok());
|
||||
PP_EXPECT(h, bad_layer_name_result.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !non_finite_opacity_result.ok());
|
||||
PP_EXPECT(h, non_finite_opacity_result.status().code == StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
void creates_minimal_project_for_roundtrip_load(pp::tests::Harness& h)
|
||||
@@ -743,6 +766,18 @@ void rejects_invalid_minimal_project_writer_inputs(pp::tests::Harness& h)
|
||||
.frame_duration_ms = 100,
|
||||
.dirty_faces = {},
|
||||
});
|
||||
const auto non_finite_opacity = create_minimal_ppi_project(pp::assets::PpiMinimalProjectConfig {
|
||||
.width = 128,
|
||||
.height = 128,
|
||||
.layer_name = "Ink",
|
||||
.layer_metadata = pp::assets::PpiLayerMetadataConfig {
|
||||
.opacity = std::numeric_limits<float>::quiet_NaN(),
|
||||
},
|
||||
.layer_count = 1,
|
||||
.frame_count = 1,
|
||||
.frame_duration_ms = 100,
|
||||
.dirty_faces = {},
|
||||
});
|
||||
const auto bad_blend_mode = create_minimal_ppi_project(pp::assets::PpiMinimalProjectConfig {
|
||||
.width = 128,
|
||||
.height = 128,
|
||||
@@ -798,6 +833,8 @@ void rejects_invalid_minimal_project_writer_inputs(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, no_layers.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !bad_opacity.ok());
|
||||
PP_EXPECT(h, bad_opacity.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !non_finite_opacity.ok());
|
||||
PP_EXPECT(h, non_finite_opacity.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !bad_blend_mode.ok());
|
||||
PP_EXPECT(h, bad_blend_mode.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !duplicate_dirty_face.ok());
|
||||
|
||||
Reference in New Issue
Block a user