vmware-labs / webassembly-language-runtimes

Wasm Language Runtimes provides popular language runtimes (Ruby, Python, …) precompiled to WebAssembly that are tested for compatibility and kept up to date when new versions of upstream languages are released
Apache License 2.0
327 stars 27 forks source link

fix: Emulated implementations for `is_readable()` and `is_writable()` by trial and error #89

Closed gzurl closed 1 year ago

gzurl commented 1 year ago

This PR provides a patch to emulate PHP's is_readable() and is_writable() functions by trial and error.

In wasi-libc stat(), since there is no user/group concept in Wasm, st_mode is initialized to 000, as well as st_uid and st_gid.

So, by default, is_readable() and is_writable() will return FALSE.

Two approaches have been discussed:

  1. Patch those methods to always return TRUE. This works for many scenarios since most PHP apps will check fopen() return value even if the is_xxxable() functions were previously called.
  2. Trial and error. To avoid the above assumption and returning fake values that might be totally wrong, a different approach is to actually try to open/write those resources and return the result.

The latter approach seems more appropriate. The only drawback is a small penalty in performance since the execution of the new checkers takes longer than simply querying the values from stat. But once PHP's cache starts hitting, performance shouldn't be affected.

gzurl commented 1 year ago

After a team conversation, we decided to release the "always returning TRUE" hack. So, I'm invalidating this PR in favor of #90.