Bug 254813 - REGRESSION(259689@main): [GLib] openFile() fails to create files
Summary: REGRESSION(259689@main): [GLib] openFile() fails to create files
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alicia Boya García
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-31 07:52 PDT by Alicia Boya García
Modified: 2023-04-25 06:49 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alicia Boya García 2023-03-31 07:52:06 PDT
How to reproduce:

$ run-webkit-httpd
$ TEST_RUNNER_TEST_PLUGIN_PATH=this_env_var_is_no_longer_used_and_shouldnt_be_required_but_that_is_work_for_another_patch \
  webkit-flatpak --gtk --debug -c \
  /app/webkit/WebKitBuild/Debug/bin/WebKitTestRunner --show-window http://localhost:8000/media-resources/media-source/media-source-seek-unbuffered.html
[...]
ERROR: writeOriginToFile: Failed to open origin file '/home/ntrrgc/.local/share/WebKitTestRunner/storage/4NoLZrGDXutAmUUf2IXlV4GkA_dI4PpgaXiB2xqjhow/4NoLZrGDXutAmUUf2IXlV4GkA_dI4PpgaXiB2xqjhow/origin'
/app/webkit/Source/WebKit/NetworkProcess/storage/StorageUtilities.h(73) : bool WebKit::writeOriginToFile(const WTF::String &, const WebCore::ClientOrigin &)

There is nothing wrong about the path above. This is the call that is being made:

auto originFileHandle = FileSystem::openFile(filePath, FileSystem::FileOpenMode::ReadWrite[, failIfFileExists = false]);

The problem is openFile() is using g_file_open_readwrite() in this code path, which fails if the file doesn't exist.

The following is a table of valid GIO functions for creating an stream with permissions requested by WebKit:

+-----------+-------------------------+----------------------------+
|   Mode    |    failIfFileExists     |            Call            |
+-----------+-------------------------+----------------------------+
| Read      | (any, will always fail) | g_file_read()              |
| Truncate  | true                    | g_file_create()            |
| Truncate  | false                   | g_file_replace()           |
| ReadWrite | true                    | g_file_create_readwrite()  |
| ReadWrite | false                   | g_file_replace_readwrite() |
+-----------+-------------------------+----------------------------+
Comment 1 Alicia Boya García 2023-04-06 07:04:47 PDT
I'm working on a fix.
Comment 2 Alicia Boya García 2023-04-07 09:32:14 PDT
This turned out to be a bigger rabbit hole than I expected. I'm not very happy with GIO's API.

The previous table I made is incorrect, as g_file_replace_readwrite() followed by a close() effectively truncates the file.
Comment 3 Alicia Boya García 2023-04-07 09:46:01 PDT
Pull request: https://github.com/WebKit/WebKit/pull/12511
Comment 4 EWS 2023-04-25 06:49:30 PDT
Committed 263367@main (78d2561b2bf7): <https://commits.webkit.org/263367@main>

Reviewed commits have been landed. Closing PR #12511 and removing active labels.