mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-01 15:18:06 +00:00
LibWeb: Disallow creating a FileAPI::FileList with a vector of files
This factory forced callers to make a list of GC-allocated FileAPI::File objects. This isn't safe - this opens a window for these files to be garbage collected before the FileList object stores / visits the list. Instead, only allow creating an empty FileList and incrementally adding files to that list.
This commit is contained in:
parent
a3a69b8ad2
commit
8b4d28b5fd
Notes:
github-actions[bot]
2024-08-19 11:30:30 +00:00
Author: https://github.com/trflynn89
Commit: 8b4d28b5fd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1111
3 changed files with 8 additions and 21 deletions
|
@ -14,23 +14,11 @@ namespace Web::FileAPI {
|
|||
|
||||
JS_DEFINE_ALLOCATOR(FileList);
|
||||
|
||||
JS::NonnullGCPtr<FileList> FileList::create(JS::Realm& realm, Vector<JS::NonnullGCPtr<File>>&& files)
|
||||
{
|
||||
return realm.heap().allocate<FileList>(realm, realm, move(files));
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<FileList> FileList::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<FileList>(realm, realm);
|
||||
}
|
||||
|
||||
FileList::FileList(JS::Realm& realm, Vector<JS::NonnullGCPtr<File>>&& files)
|
||||
: Bindings::PlatformObject(realm)
|
||||
, m_files(move(files))
|
||||
{
|
||||
m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = 1 };
|
||||
}
|
||||
|
||||
FileList::FileList(JS::Realm& realm)
|
||||
: Bindings::PlatformObject(realm)
|
||||
{
|
||||
|
|
|
@ -22,9 +22,10 @@ class FileList
|
|||
JS_DECLARE_ALLOCATOR(FileList);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static JS::NonnullGCPtr<FileList> create(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<FileList> create(JS::Realm&);
|
||||
|
||||
void add_file(JS::NonnullGCPtr<File> file) { m_files.append(file); }
|
||||
|
||||
virtual ~FileList() override;
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dfn-length
|
||||
|
@ -49,7 +50,6 @@ public:
|
|||
virtual WebIDL::ExceptionOr<void> deserialization_steps(ReadonlySpan<u32> const& serialized, size_t& position, HTML::DeserializationMemory&) override;
|
||||
|
||||
private:
|
||||
FileList(JS::Realm&, Vector<JS::NonnullGCPtr<File>>&&);
|
||||
explicit FileList(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue