New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle YAML.load_file on Psych 4 #392
Conversation
89158d4
to
a95c258
Compare
Ok, found an interesting bug: File.write("foo.json", "true")
JSON.load_file("foo.json) # => true
YAML.load_file("foo.json) # EOFError It might seem weird, but since YAML is a superset of JSON, it's not totally invalid, and even if it was we should still fallback properly. Until now it worked because JSON and YAML caches had the same format. But now that YAML caches have a prefix to indicate wether they are safe mode compatible, YAML can't read JSON caches and vice-versa. So each cache would need a key prefix or something. |
aa7d24a
to
d767c21
Compare
d767c21
to
f562d2a
Compare
The Windows segfault seem consistent and legit. |
24af1d4
to
8400bd0
Compare
Context: https://bugs.ruby-lang.org/issues/18492 Rescuing exceptions from a C-extension is complicated, and even seem a bit broken on Windows. It's much simpler to return a special unique value, and likely is more performant too.
7244cef
to
f210df9
Compare
Since I ran into https://bugs.ruby-lang.org/issues/18492, I had to refactor further to workaround the issue. Instead of raising |
This can cause issues with older versions of Bootsnap Ref: Shopify/bootsnap#392 (comment)
Kind of a fix for #375. Not exactly because it doesn't add support for
safe_load_file
, but forYAML.load_file
onpsych 4
, which is the most used interface.The idea is that we store a boolean prefix in the cache. When we precompile we try to parse in safe mode, if it fails we fallback to unsafe parsing.
When loading from cache, we know if
load_file
orunsafe_load_file
is used.unsafe_load_file
can use cache generated in safe mode, butload_file
won't use caches generated viaunsafe_load_file
.This is a rough prototype, it misses a few bits and needs a lot more testing.