mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
LibGfx+icc: Look at profile_size field
This trims the input bytes to the profile size stored in the file. Alternatively, we could reject files where the stored size doesn't match the handed in size. But ICC profiles can be embedded in other files, and those could conceivably pad the ICC profile data some.
This commit is contained in:
parent
7d4ec4fecf
commit
7ae97c9fc4
3 changed files with 29 additions and 0 deletions
|
@ -116,6 +116,22 @@ struct ICCHeader {
|
||||||
};
|
};
|
||||||
static_assert(sizeof(ICCHeader) == 128);
|
static_assert(sizeof(ICCHeader) == 128);
|
||||||
|
|
||||||
|
ErrorOr<u32> parse_size(ICCHeader const& header, ReadonlyBytes icc_bytes)
|
||||||
|
{
|
||||||
|
// ICC v4, 7.2.2 Profile size field
|
||||||
|
// "The value in the profile size field shall be the exact size obtained by combining the profile header,
|
||||||
|
// the tag table, and the tagged element data, including the pad bytes for the last tag."
|
||||||
|
|
||||||
|
// Valid files have enough data for profile header and tag table entry count.
|
||||||
|
if (header.profile_size < sizeof(ICCHeader) + sizeof(u32))
|
||||||
|
return Error::from_string_literal("ICC::Profile: Profile size too small");
|
||||||
|
|
||||||
|
if (header.profile_size > icc_bytes.size())
|
||||||
|
return Error::from_string_literal("ICC::Profile: Profile size larger than input data");
|
||||||
|
|
||||||
|
return header.profile_size;
|
||||||
|
}
|
||||||
|
|
||||||
Optional<PreferredCMMType> parse_preferred_cmm_type(ICCHeader const& header)
|
Optional<PreferredCMMType> parse_preferred_cmm_type(ICCHeader const& header)
|
||||||
{
|
{
|
||||||
// ICC v4, 7.2.3 Preferred CMM type field
|
// ICC v4, 7.2.3 Preferred CMM type field
|
||||||
|
@ -504,6 +520,7 @@ ErrorOr<NonnullRefPtr<Profile>> Profile::try_load_from_externally_owned_memory(R
|
||||||
auto header = *bit_cast<ICCHeader const*>(bytes.data());
|
auto header = *bit_cast<ICCHeader const*>(bytes.data());
|
||||||
|
|
||||||
TRY(parse_file_signature(header));
|
TRY(parse_file_signature(header));
|
||||||
|
profile->m_on_disk_size = TRY(parse_size(header, bytes));
|
||||||
profile->m_preferred_cmm_type = parse_preferred_cmm_type(header);
|
profile->m_preferred_cmm_type = parse_preferred_cmm_type(header);
|
||||||
profile->m_version = TRY(parse_version(header));
|
profile->m_version = TRY(parse_version(header));
|
||||||
profile->m_device_class = TRY(parse_device_class(header));
|
profile->m_device_class = TRY(parse_device_class(header));
|
||||||
|
@ -521,6 +538,10 @@ ErrorOr<NonnullRefPtr<Profile>> Profile::try_load_from_externally_owned_memory(R
|
||||||
profile->m_id = TRY(parse_profile_id(header, bytes));
|
profile->m_id = TRY(parse_profile_id(header, bytes));
|
||||||
TRY(parse_reserved(header));
|
TRY(parse_reserved(header));
|
||||||
|
|
||||||
|
bytes = bytes.trim(header.profile_size);
|
||||||
|
bytes = bytes.slice(sizeof(ICCHeader));
|
||||||
|
// FIXME: Read tag table.
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,7 @@ public:
|
||||||
// For non-DeviceLink profiles, always PCSXYZ or PCSLAB.
|
// For non-DeviceLink profiles, always PCSXYZ or PCSLAB.
|
||||||
ColorSpace connection_space() const { return m_connection_space; }
|
ColorSpace connection_space() const { return m_connection_space; }
|
||||||
|
|
||||||
|
u32 on_disk_size() const { return m_on_disk_size; }
|
||||||
time_t creation_timestamp() const { return m_creation_timestamp; }
|
time_t creation_timestamp() const { return m_creation_timestamp; }
|
||||||
PrimaryPlatform primary_platform() const { return m_primary_platform; }
|
PrimaryPlatform primary_platform() const { return m_primary_platform; }
|
||||||
Flags flags() const { return m_flags; }
|
Flags flags() const { return m_flags; }
|
||||||
|
@ -237,6 +238,7 @@ public:
|
||||||
static Crypto::Hash::MD5::DigestType compute_id(ReadonlyBytes);
|
static Crypto::Hash::MD5::DigestType compute_id(ReadonlyBytes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
u32 m_on_disk_size { 0 };
|
||||||
Optional<PreferredCMMType> m_preferred_cmm_type;
|
Optional<PreferredCMMType> m_preferred_cmm_type;
|
||||||
Version m_version;
|
Version m_version;
|
||||||
DeviceClass m_device_class;
|
DeviceClass m_device_class;
|
||||||
|
|
|
@ -67,5 +67,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
out_optional("creator", profile->creator());
|
out_optional("creator", profile->creator());
|
||||||
out_optional("id", profile->id());
|
out_optional("id", profile->id());
|
||||||
|
|
||||||
|
size_t profile_disk_size = icc_file->size();
|
||||||
|
if (profile_disk_size != profile->on_disk_size()) {
|
||||||
|
VERIFY(profile_disk_size > profile->on_disk_size());
|
||||||
|
outln("{} trailing bytes after profile data", profile_disk_size - profile->on_disk_size());
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue