Skip to content
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

psych/class_loader.rb:99:in `find': Tried to load unspecified class: Gem::Specification (Psych::DisallowedClass) #1895

Closed
jordansissel opened this issue May 1, 2022 · 3 comments · Fixed by #1898

Comments

@jordansissel
Copy link
Owner

jordansissel commented May 1, 2022

  • When doing fpm -s gem -t deb rails
  • On Ruby versions 3.1.0 or newer

fpm tries to load a downloaded gem's metadata, it can fail with an error

psych/class_loader.rb:99:in `find': Tried to load unspecified class: Gem::Specification (Psych::DisallowedClass)

This seems to be a new failure caused by an upstream ruby or psych change. This ruby psych issue seems related: ruby/psych#487

The above ruby psych change mentions that safe_load is now the default (YAML.load is "safe_load") and the previous load method has been renamed unsafe_load.

Need to dig a bit more to figure out the best solution that does safe loading, but for now, calling unsafe_load when it's available is probably a short fix.

jordansissel added a commit that referenced this issue May 2, 2022
On older rubies, YAML.load _is_ the unsafe load method. At some point,
Ruby 3.1.0 / Psych 4(?) made two renames:

* YAML.load -> YAML.unsafe_load
* YAML.safe_load -> YAML.load

A quick test is to try converting a gem. This would fail if `YAML.load`
was the "safe" method because it would fail with this message:

    Tried to load unspecified class: Gem::Specification (Psych::DisallowedClass

`fpm -s gem -t empty rails` will crash on Ruby 3.1.0 prior to this
commit.

Fixes #1895
jordansissel added a commit that referenced this issue May 20, 2022
On older rubies, YAML.load _is_ the unsafe load method. At some point,
Ruby 3.1.0 / Psych 4(?) made two renames:

* YAML.load -> YAML.unsafe_load
* YAML.safe_load -> YAML.load

A quick test is to try converting a gem. This would fail if `YAML.load`
was the "safe" method because it would fail with this message:

    Tried to load unspecified class: Gem::Specification (Psych::DisallowedClass

`fpm -s gem -t empty rails` will crash on Ruby 3.1.0 prior to this
commit.

Fixes #1895

Add necessary classes to safely load yaml from gem specs
jordansissel added a commit that referenced this issue May 20, 2022
On older rubies, YAML.load _is_ the unsafe load method. At some point,
Ruby 3.1.0 / Psych 4(?) made two renames:

* YAML.load -> YAML.unsafe_load
* YAML.safe_load -> YAML.load

A quick test is to try converting a gem. This would fail if `YAML.load`
was the "safe" method because it would fail with this message:

    Tried to load unspecified class: Gem::Specification (Psych::DisallowedClass

`fpm -s gem -t empty rails` will crash on Ruby 3.1.0 prior to this
commit.

Fixes #1895

Add necessary classes to safely load yaml from gem specs
@jordansissel
Copy link
Owner Author

#1898 fixes this.

@noraj
Copy link

noraj commented Jun 9, 2022

$ ruby --version 
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux]
$ fpm --version
1.14.2
$ fpm -s gem -t deb haiti-hash                                                                                                                                                                                                              
/home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/class_loader.rb:99:in `find': Tried to load unspecified class: Gem::Specification (Psych::DisallowedClass)                                                                        
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/class_loader.rb:28:in `load'                                                                                                                                         
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:424:in `resolve_class'                                                                                                                           
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:213:in `visit_Psych_Nodes_Mapping'                                                                                                               
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'                                                                                                                                    
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'                                                                                                                                    
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'                                                                                                                                   
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:318:in `visit_Psych_Nodes_Document'                                                                                                              
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'                                                                                                                                    
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'                                                                                                                                    
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'                                                                                                                                   
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych.rb:335:in `safe_load'                                                                                                                                                
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/3.1.0/psych.rb:370:in `load'                                                                                                                                                     
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/fpm-1.14.2/lib/fpm/package/gem.rb:140:in `load_package_info'                                                                                                     
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/fpm-1.14.2/lib/fpm/package/gem.rb:85:in `input'                                                                                                                  
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/fpm-1.14.2/lib/fpm/command.rb:352:in `block in execute'
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/fpm-1.14.2/lib/fpm/command.rb:351:in `each'
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/fpm-1.14.2/lib/fpm/command.rb:351:in `execute'
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/clamp-1.0.1/lib/clamp/command.rb:68:in `run'
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/fpm-1.14.2/lib/fpm/command.rb:574:in `run' 
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/clamp-1.0.1/lib/clamp/command.rb:133:in `run'
        from /home/noraj/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/fpm-1.14.2/bin/fpm:7:in `<top (required)>' 
        from /home/noraj/.asdf/installs/ruby/3.1.1/bin/fpm:25:in `load'
        from /home/noraj/.asdf/installs/ruby/3.1.1/bin/fpm:25:in `<main>'

#1898 has been merged 2022/05/20 but last release/tag 1.14.2 is from 2022/03/31 so the fix is not live yet :(

Could you release a 1.14.3 please?

jordansissel added a commit that referenced this issue Nov 4, 2022
On older rubies, YAML.load _is_ the unsafe load method. At some point,
Ruby 3.1.0 / Psych 4(?) made two renames:

* YAML.load -> YAML.unsafe_load
* YAML.safe_load -> YAML.load

A quick test is to try converting a gem. This would fail if `YAML.load`
was the "safe" method because it would fail with this message:

    Tried to load unspecified class: Gem::Specification (Psych::DisallowedClass

`fpm -s gem -t empty rails` will crash on Ruby 3.1.0 prior to this
commit.

Fixes #1895

Add necessary classes to safely load yaml from gem specs
@jordansissel
Copy link
Owner Author

fpm 1.15.0 is released and, I believe, has resolve this issue. Please let me know if you find otherwise in a new issue (if a new problem) or this issue (if same problem)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants