/yaml-sample

Primary LanguageMakefileCreative Commons Zero v1.0 UniversalCC0-1.0

sample.wasm

特定の状況でYAML.load_file を利用すると unreachable エラーにより停止することを再現したプロジェクトです。

どういうコードか

src/i18n.yamlYAML.load_file を使ってパースするコードです。sample_pass.rb は正常終了しますが、sample_fail.rbはエラーで停止してしまいます。

実行例

$ make
[省略]
$ wasmtime run sample.wasm -- /src/sample_pass.rb
target: /src/sample_pass.rb
/src/i18n.yaml [ok]
$ wasmtime run sample.wasm -- /src/sample_fail.rb
target: /src/sample_fail.rb
/src/i18n.yamlError: failed to run main module `sample.wasm`

Caused by:
    0: failed to invoke command default
    1: wasm trap: wasm `unreachable` instruction executed
       wasm backtrace:
           0: 0x5bd7ab - <unknown>!<wasm function 6990>
           1: 0x603703 - <unknown>!<wasm function 7425>
           2: 0x4872 - <unknown>!<wasm function 38>
           3: 0x6177f8 - <unknown>!<wasm function 7567>
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable to may show more debugging information

失敗例と成功例の差分

sample_pass.rbはトップレベルでYAML.load_fileを呼び出していますが、sample_fail.rbInteger#timesのブロック内でYAML.load_fileを呼び出しています。

Author

酒田 シンジ(@ysakasin