Error loading Psych gem specification on Ruby 3.2.2
noamansaiyed opened this issue · 1 comments
noamansaiyed commented
Error loading Psych gem specification on Ruby 3.2.2
Environment: Docker image ruby:3.2.2-buster
Issue: When running the command gem specification --yaml psych | ruby -ryaml -e "pak = YAML::load(STDIN.read); puts pak.name"
on Ruby 3.2.2, I encountered the following error:
```
root@4d406556a868:/# gem specification --yaml psych | ruby -ryaml -e "pak = YAML::load(STDIN.read); puts pak.name"
/usr/local/lib/ruby/3.2.0/psych/class_loader.rb:99:in `find': Tried to load unspecified class: Gem::Specification (Psych::DisallowedClass)
from /usr/local/lib/ruby/3.2.0/psych/class_loader.rb:28:in `load'
from /usr/local/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:426:in `resolve_class'
from /usr/local/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:215:in `visit_Psych_Nodes_Mapping'
from /usr/local/lib/ruby/3.2.0/psych/visitors/visitor.rb:30:in `visit'
from /usr/local/lib/ruby/3.2.0/psych/visitors/visitor.rb:6:in `accept'
from /usr/local/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:35:in `accept'
from /usr/local/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:320:in `visit_Psych_Nodes_Document'
from /usr/local/lib/ruby/3.2.0/psych/visitors/visitor.rb:30:in `visit'
from /usr/local/lib/ruby/3.2.0/psych/visitors/visitor.rb:6:in `accept'
from /usr/local/lib/ruby/3.2.0/psych/visitors/to_ruby.rb:35:in `accept'
from /usr/local/lib/ruby/3.2.0/psych.rb:334:in `safe_load'
from /usr/local/lib/ruby/3.2.0/psych.rb:369:in `load'
from -e:1:in `<main>'
root@4d406556a868:/# ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
root@4d406556a868:/# gem list | grep psych
psych (default: 5.0.1)
```
Steps to Reproduce:
- Install Docker.
- Run docker command:
docker run -it --rm --entrypoint bash ruby:3.2.2-slim-buster
- Run the command:
gem specification --yaml psych | ruby -ryaml -e "pak = YAML::load(STDIN.read); puts pak.name"
Expected Behavior: The command should return the name of the Psych gem.
Actual Behavior: The command produces the error above.
Additional Information:
I noticed that the same command works on Ruby 2.7 with Psych version 3.1.0. It seems like there might be an incompatibility between Ruby 3.2.2 and Psych 5.0.1.
```
root@6eec334fcff7:/# gem specification --yaml psych | ruby -ryaml -e "pak = YAML::load(STDIN.read); puts pak.name"
psych
root@6eec334fcff7:/# ruby -v
ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-linux]
root@6eec334fcff7:/# gem list | grep psych
psych (default: 3.1.0)
```
To reproduce the working behavior on Ruby 2.7, follow these steps:
- Install Docker.
- Run docker command:
docker run -it --rm --entrypoint bash ruby:2.7-slim-buster
- Run the command:
gem specification --yaml psych | ruby -ryaml -e "pak = YAML::load(STDIN.read); puts pak.name"
hsbt commented
It's expected changes in Psych 5.0 and Ruby 3.2. Use permitted_classes
for Psych.load