-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Use safe Marshal deserialization for dependency API response. #6141
Conversation
- adds Bundler#safe_load_marshal and Bundler::SAFE_MARSHAL_CLASSES listing safe classes to deserialize
@@ -39,6 +39,16 @@ module Bundler | |||
environment_preserver.replace_with_backup | |||
SUDO_MUTEX = Thread::Mutex.new | |||
|
|||
SAFE_MARSHAL_CLASSES = [Symbol, TrueClass, String, Array, Hash].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I'm not sure why TrueClass
is needed, but it is passed to proc even not part of the structure.
irb(main):013:0> simple_structure = { "name" => [:abc] }
=> {"name"=>[:abc]}
irb(main):014:0> Marshal.load(Marshal.dump(simple_structure), ->(object) { object.tap { puts object.class }})
TrueClass
String
Symbol
Array
Hash
=> {"name"=>[:abc]}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to strip this down to string deserialization.
Marshal.load(Marshal.dump('string'), ->(o) { o.tap { puts o.class } })
String
TrueClass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case it's useful, I think TrueClass
is related to the string encoding. That seems to be what the ET at the end of the dump is about:
Marshal.dump('string')
#=> "\x04\bI\"\vstring\x06:\x06ET"
whereas we get false
in this case:
Marshal.dump('string'.encode!('ASCII'))
#=> "\x04\bI\"\vstring\x06:\x06EF"
or a string for other encodings:
Marshal.dump('string'.encode!('ISO-8859-1'))
#=> "\x04\bI\"\vstring\x06:\rencoding\"\x0FISO-8859-1"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems good for the dependency API! Can we also use SafeMarshal for loading Marshal.4.8.specs.gz
and latest_specs
? Could be in another PR if that's easier.
@indirect those includes |
ℹ️ I'm looking at introducing real-word spec to cover the real response from Dependency API as well.