diff options
author | Nico Weber <thakis@chromium.org> | 2023-05-03 19:49:06 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-04 16:11:07 +0200 |
commit | 54448040eca2cf98ac4d51092d3dbd57c5d5573a (patch) | |
tree | 5c9f4bbecf5c256adaaca686dabae7c4acb258a4 /Userland | |
parent | 0079fad785437ac8522a770dcb90804d8156605c (diff) | |
download | serenity-54448040eca2cf98ac4d51092d3dbd57c5d5573a.zip |
ICC: Verify curve types have valid types
LutAToBTagData::from_bytes() and LutBToATagData::from_bytes() already
reject curves for which this isn't true with an error.
Ensure potential future callers of the constructors get it right too.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGfx/ICC/TagTypes.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/ICC/TagTypes.h | 10 |
2 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp index b012a8f024..ddd261bfb6 100644 --- a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp +++ b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp @@ -388,6 +388,23 @@ static ErrorOr<Vector<LutCurveType>> read_curves(ReadonlyBytes bytes, u32 offset return curves; } +static bool is_valid_curve(LutCurveType const& curve) +{ + return curve->type() == CurveTagData::Type || curve->type() == ParametricCurveTagData::Type; +} + +bool are_valid_curves(Optional<Vector<LutCurveType>> const& curves) +{ + if (!curves.has_value()) + return true; + + for (auto const& curve : curves.value()) { + if (!is_valid_curve(curve)) + return false; + } + return true; +} + ErrorOr<NonnullRefPtr<LutAToBTagData>> LutAToBTagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size) { // ICC v4, 10.12 lutAToBType diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.h b/Userland/Libraries/LibGfx/ICC/TagTypes.h index 751207f8cf..67a9a8162f 100644 --- a/Userland/Libraries/LibGfx/ICC/TagTypes.h +++ b/Userland/Libraries/LibGfx/ICC/TagTypes.h @@ -369,6 +369,8 @@ struct CLUTData { using LutCurveType = NonnullRefPtr<TagData>; // FIXME: Variant<CurveTagData, ParametricCurveTagData> instead? +bool are_valid_curves(Optional<Vector<LutCurveType>> const& curves); + // ICC v4, 10.12 lutAToBType class LutAToBTagData : public TagData { public: @@ -394,6 +396,10 @@ public: VERIFY(number_of_input_channels == number_of_output_channels || m_clut.has_value()); VERIFY(m_a_curves.has_value() == m_clut.has_value()); VERIFY(m_m_curves.has_value() == m_e.has_value()); + + VERIFY(are_valid_curves(m_a_curves)); + VERIFY(are_valid_curves(m_m_curves)); + VERIFY(are_valid_curves(m_b_curves)); } u8 number_of_input_channels() const { return m_number_of_input_channels; } @@ -448,6 +454,10 @@ public: VERIFY(m_e.has_value() == m_m_curves.has_value()); VERIFY(m_clut.has_value() == m_a_curves.has_value()); VERIFY(number_of_input_channels == number_of_output_channels || m_clut.has_value()); + + VERIFY(are_valid_curves(m_b_curves)); + VERIFY(are_valid_curves(m_m_curves)); + VERIFY(are_valid_curves(m_a_curves)); } u8 number_of_input_channels() const { return m_number_of_input_channels; } |