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:
Nico Weber 2023-05-03 19:49:06 -04:00 committed by Andreas Kling
parent 0079fad785
commit 54448040ec
Notes: sideshowbarker 2024-07-16 21:34:08 +09:00
2 changed files with 27 additions and 0 deletions

View file

@ -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

View file

@ -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; }