mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:47:46 +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
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;
|
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)
|
ErrorOr<NonnullRefPtr<LutAToBTagData>> LutAToBTagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size)
|
||||||
{
|
{
|
||||||
// ICC v4, 10.12 lutAToBType
|
// ICC v4, 10.12 lutAToBType
|
||||||
|
|
|
@ -369,6 +369,8 @@ struct CLUTData {
|
||||||
|
|
||||||
using LutCurveType = NonnullRefPtr<TagData>; // FIXME: Variant<CurveTagData, ParametricCurveTagData> instead?
|
using LutCurveType = NonnullRefPtr<TagData>; // FIXME: Variant<CurveTagData, ParametricCurveTagData> instead?
|
||||||
|
|
||||||
|
bool are_valid_curves(Optional<Vector<LutCurveType>> const& curves);
|
||||||
|
|
||||||
// ICC v4, 10.12 lutAToBType
|
// ICC v4, 10.12 lutAToBType
|
||||||
class LutAToBTagData : public TagData {
|
class LutAToBTagData : public TagData {
|
||||||
public:
|
public:
|
||||||
|
@ -394,6 +396,10 @@ public:
|
||||||
VERIFY(number_of_input_channels == number_of_output_channels || m_clut.has_value());
|
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_a_curves.has_value() == m_clut.has_value());
|
||||||
VERIFY(m_m_curves.has_value() == m_e.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; }
|
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_e.has_value() == m_m_curves.has_value());
|
||||||
VERIFY(m_clut.has_value() == m_a_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(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; }
|
u8 number_of_input_channels() const { return m_number_of_input_channels; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue