1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:28:12 +00:00

LibWeb: Add convenience methods {,de}serialize_{u,i}64()

To avoid differing logic for serializing and deserializing similar
types, move the logic into separate helpers.

Also, adds security checks like VERIFY to avoid reading past the end of
the serialized data. If we try to read past the end of the serialized
data, either our program logic is wrong or our serialized data has
somehow been corrupted. Therefore, at least currently, it is better to
crash by VERIFYing.
This commit is contained in:
Kenneth Myhra 2024-03-02 21:33:07 +01:00 committed by Andrew Kaster
parent d269ac611e
commit 4751ab9f0b
3 changed files with 38 additions and 11 deletions

View file

@ -106,7 +106,7 @@ WebIDL::ExceptionOr<void> File::serialization_steps(HTML::SerializationRecord& r
TRY(HTML::serialize_string(vm, record, m_name));
// 4. Set serialized.[[LastModified]] to the value of values lastModified attribute.
record.append(bit_cast<u32*>(&m_last_modified), 2);
HTML::serialize_i64(record, m_last_modified);
return {};
}
@ -128,10 +128,7 @@ WebIDL::ExceptionOr<void> File::deserialization_steps(ReadonlySpan<u32> const& r
m_name = TRY(HTML::deserialize_string(vm, record, position));
// 4. Initialize the value of values lastModified attribute to serialized.[[LastModified]].
u32 bits[2] = {};
bits[0] = record[position++];
bits[1] = record[position++];
m_last_modified = *bit_cast<i64*>(&bits);
m_last_modified = HTML::deserialize_i64(record, position);
return {};
}