mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
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.
This commit is contained in:
parent
0079fad785
commit
54448040ec
Notes:
sideshowbarker
2024-07-16 21:34:08 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/54448040ec Pull-request: https://github.com/SerenityOS/serenity/pull/18629
2 changed files with 27 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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; }
|
||||
|
|
Loading…
Reference in a new issue