Changeset 291014 in webkit


Ignore:
Timestamp:
Mar 8, 2022 3:04:42 PM (4 months ago)
Author:
sihui_liu@apple.com
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):

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r291010 r291014  
     12022-03-08  Sihui Liu  <sihui_liu@apple.com>
     2
     3        File System Access: throw exception if file or directory cannot be accessed in file system
     4        https://bugs.webkit.org/show_bug.cgi?id=237537
     5
     6        Reviewed by Youenn Fablet.
     7
     8        When a FileSystemHandle is created, we will ensure that corresponding directory or file exists (create the
     9        directory or file if it does not exist yet). However, we did not check the result of the file system calls.
     10        That means, we may fail to create the file (e.g. due to no disk space, or cases in rdar://89291566), but we
     11        still return success to the FileSystemHandle creation request. We should fix this by checking the file system
     12        call's result before completing the request. 
     13
     14        * NetworkProcess/storage/FileSystemStorageHandle.cpp:
     15        (WebKit::FileSystemStorageHandle::create):
     16        (WebKit::FileSystemStorageHandle::FileSystemStorageHandle):
     17        * NetworkProcess/storage/FileSystemStorageHandle.h:
     18        * NetworkProcess/storage/FileSystemStorageManager.cpp:
     19        (WebKit::FileSystemStorageManager::createHandle):
     20
    1212022-03-08  Commit Queue  <commit-queue@webkit.org>
    222
  • trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp

    r290998 r291014  
    4040#endif
    4141
     42std::unique_ptr<FileSystemStorageHandle> FileSystemStorageHandle::create(FileSystemStorageManager& manager, Type type, String&& path, String&& name)
     43{
     44    bool canAccess = false;
     45    switch (type) {
     46    case FileSystemStorageHandle::Type::Directory:
     47        canAccess = FileSystem::makeAllDirectories(path);
     48        break;
     49    case FileSystemStorageHandle::Type::File:
     50        if (auto handle = FileSystem::openFile(path, FileSystem::FileOpenMode::Write); FileSystem::isHandleValid(handle)) {
     51            FileSystem::closeFile(handle);
     52            canAccess = true;
     53        }
     54        break;
     55    case FileSystemStorageHandle::Type::Any:
     56        ASSERT_NOT_REACHED();
     57    }
     58
     59    if (!canAccess)
     60        return nullptr;
     61
     62    return std::unique_ptr<FileSystemStorageHandle>(new FileSystemStorageHandle(manager, type, WTFMove(path), WTFMove(name)));
     63}
     64
    4265FileSystemStorageHandle::FileSystemStorageHandle(FileSystemStorageManager& manager, Type type, String&& path, String&& name)
    4366    : m_identifier(WebCore::FileSystemHandleIdentifier::generateThreadSafe())
     
    4871{
    4972    ASSERT(!m_path.isEmpty());
    50 
    51     switch (m_type) {
    52     case FileSystemStorageHandle::Type::Directory:
    53         FileSystem::makeAllDirectories(m_path);
    54         return;
    55     case FileSystemStorageHandle::Type::File:
    56         if (!FileSystem::fileExists(m_path)) {
    57             auto handle = FileSystem::openFile(m_path, FileSystem::FileOpenMode::Write);
    58             FileSystem::closeFile(handle);
    59         }
    60         return;
    61     case FileSystemStorageHandle::Type::Any:
    62         ASSERT_NOT_REACHED();
    63     }
    6473}
    6574
  • trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h

    r287156 r291014  
    4444public:
    4545    enum class Type : uint8_t { File, Directory, Any };
    46     FileSystemStorageHandle(FileSystemStorageManager&, Type, String&& path, String&& name);
     46    static std::unique_ptr<FileSystemStorageHandle> create(FileSystemStorageManager&, Type, String&& path, String&& name);
    4747
    4848    WebCore::FileSystemHandleIdentifier identifier() const { return m_identifier; }
     
    6666
    6767private:
     68    FileSystemStorageHandle(FileSystemStorageManager&, Type, String&& path, String&& name);
    6869    Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError> requestCreateHandle(IPC::Connection::UniqueID, Type, String&& name, bool createIfNecessary);
    6970
  • trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp

    r289012 r291014  
    7878    }
    7979
    80     auto newHandle = makeUnique<FileSystemStorageHandle>(*this, type, WTFMove(path), WTFMove(name));
     80    auto newHandle = FileSystemStorageHandle::create(*this, type, WTFMove(path), WTFMove(name));
     81    if (!newHandle)
     82        return makeUnexpected(FileSystemStorageError::Unknown);
    8183    auto newHandleIdentifier = newHandle->identifier();
    8284    m_handlesByConnection.ensure(connection, [&] {
Note: See TracChangeset for help on using the changeset viewer.