Title: [291014] trunk/Source/WebKit
Revision
291014
Author
[email protected]
Date
2022-03-08 15:04:42 -0800 (Tue, 08 Mar 2022)

Log Message

File System Access: throw exception if file or directory cannot be accessed in file system
https://bugs.webkit.org/show_bug.cgi?id=237537

Reviewed by Youenn Fablet.

When a FileSystemHandle is created, we will ensure that corresponding directory or file exists (create the
directory or file if it does not exist yet). However, we did not check the result of the file system calls.
That means, we may fail to create the file (e.g. due to no disk space, or cases in rdar://89291566), but we
still return success to the FileSystemHandle creation request. We should fix this by checking the file system
call's result before completing the request.

* NetworkProcess/storage/FileSystemStorageHandle.cpp:
(WebKit::FileSystemStorageHandle::create):
(WebKit::FileSystemStorageHandle::FileSystemStorageHandle):
* NetworkProcess/storage/FileSystemStorageHandle.h:
* NetworkProcess/storage/FileSystemStorageManager.cpp:
(WebKit::FileSystemStorageManager::createHandle):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (291013 => 291014)


--- trunk/Source/WebKit/ChangeLog	2022-03-08 22:18:01 UTC (rev 291013)
+++ trunk/Source/WebKit/ChangeLog	2022-03-08 23:04:42 UTC (rev 291014)
@@ -1,3 +1,23 @@
+2022-03-08  Sihui Liu  <[email protected]>
+
+        File System Access: throw exception if file or directory cannot be accessed in file system
+        https://bugs.webkit.org/show_bug.cgi?id=237537
+
+        Reviewed by Youenn Fablet.
+
+        When a FileSystemHandle is created, we will ensure that corresponding directory or file exists (create the 
+        directory or file if it does not exist yet). However, we did not check the result of the file system calls.
+        That means, we may fail to create the file (e.g. due to no disk space, or cases in rdar://89291566), but we 
+        still return success to the FileSystemHandle creation request. We should fix this by checking the file system
+        call's result before completing the request.  
+
+        * NetworkProcess/storage/FileSystemStorageHandle.cpp:
+        (WebKit::FileSystemStorageHandle::create):
+        (WebKit::FileSystemStorageHandle::FileSystemStorageHandle):
+        * NetworkProcess/storage/FileSystemStorageHandle.h:
+        * NetworkProcess/storage/FileSystemStorageManager.cpp:
+        (WebKit::FileSystemStorageManager::createHandle):
+
 2022-03-08  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r291006.

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp (291013 => 291014)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp	2022-03-08 22:18:01 UTC (rev 291013)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp	2022-03-08 23:04:42 UTC (rev 291014)
@@ -39,30 +39,39 @@
 constexpr char pathSeparator = '/';
 #endif
 
-FileSystemStorageHandle::FileSystemStorageHandle(FileSystemStorageManager& manager, Type type, String&& path, String&& name)
-    : m_identifier(WebCore::FileSystemHandleIdentifier::generateThreadSafe())
-    , m_manager(manager)
-    , m_type(type)
-    , m_path(WTFMove(path))
-    , m_name(WTFMove(name))
+std::unique_ptr<FileSystemStorageHandle> FileSystemStorageHandle::create(FileSystemStorageManager& manager, Type type, String&& path, String&& name)
 {
-    ASSERT(!m_path.isEmpty());
-
-    switch (m_type) {
+    bool canAccess = false;
+    switch (type) {
     case FileSystemStorageHandle::Type::Directory:
-        FileSystem::makeAllDirectories(m_path);
-        return;
+        canAccess = FileSystem::makeAllDirectories(path);
+        break;
     case FileSystemStorageHandle::Type::File:
-        if (!FileSystem::fileExists(m_path)) {
-            auto handle = FileSystem::openFile(m_path, FileSystem::FileOpenMode::Write);
+        if (auto handle = FileSystem::openFile(path, FileSystem::FileOpenMode::Write); FileSystem::isHandleValid(handle)) {
             FileSystem::closeFile(handle);
+            canAccess = true;
         }
-        return;
+        break;
     case FileSystemStorageHandle::Type::Any:
         ASSERT_NOT_REACHED();
     }
+
+    if (!canAccess)
+        return nullptr;
+
+    return std::unique_ptr<FileSystemStorageHandle>(new FileSystemStorageHandle(manager, type, WTFMove(path), WTFMove(name)));
 }
 
+FileSystemStorageHandle::FileSystemStorageHandle(FileSystemStorageManager& manager, Type type, String&& path, String&& name)
+    : m_identifier(WebCore::FileSystemHandleIdentifier::generateThreadSafe())
+    , m_manager(manager)
+    , m_type(type)
+    , m_path(WTFMove(path))
+    , m_name(WTFMove(name))
+{
+    ASSERT(!m_path.isEmpty());
+}
+
 void FileSystemStorageHandle::close()
 {
     if (!m_manager)

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h (291013 => 291014)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h	2022-03-08 22:18:01 UTC (rev 291013)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h	2022-03-08 23:04:42 UTC (rev 291014)
@@ -43,7 +43,7 @@
     WTF_MAKE_FAST_ALLOCATED;
 public:
     enum class Type : uint8_t { File, Directory, Any };
-    FileSystemStorageHandle(FileSystemStorageManager&, Type, String&& path, String&& name);
+    static std::unique_ptr<FileSystemStorageHandle> create(FileSystemStorageManager&, Type, String&& path, String&& name);
 
     WebCore::FileSystemHandleIdentifier identifier() const { return m_identifier; }
     const String& path() const { return m_path; }
@@ -65,6 +65,7 @@
     std::optional<WebCore::FileSystemSyncAccessHandleIdentifier> activeSyncAccessHandle() const { return m_activeSyncAccessHandle; }
 
 private:
+    FileSystemStorageHandle(FileSystemStorageManager&, Type, String&& path, String&& name);
     Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError> requestCreateHandle(IPC::Connection::UniqueID, Type, String&& name, bool createIfNecessary);
 
     WebCore::FileSystemHandleIdentifier m_identifier;

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp (291013 => 291014)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp	2022-03-08 22:18:01 UTC (rev 291013)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp	2022-03-08 23:04:42 UTC (rev 291014)
@@ -77,7 +77,9 @@
         }
     }
 
-    auto newHandle = makeUnique<FileSystemStorageHandle>(*this, type, WTFMove(path), WTFMove(name));
+    auto newHandle = FileSystemStorageHandle::create(*this, type, WTFMove(path), WTFMove(name));
+    if (!newHandle)
+        return makeUnexpected(FileSystemStorageError::Unknown);
     auto newHandleIdentifier = newHandle->identifier();
     m_handlesByConnection.ensure(connection, [&] {
         return HashSet<WebCore::FileSystemHandleIdentifier> { };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to