Skip to content

Commit 3593ade

Browse files
authored
Merge pull request #6655 from rubygems/safeyaml-false
add FalseClass and Time to the SafeMarshal list
2 parents 2e94a6a + b8c277c commit 3593ade

File tree

4 files changed

+69
-18
lines changed

4 files changed

+69
-18
lines changed

Manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ bundler/lib/bundler/rubygems_ext.rb
180180
bundler/lib/bundler/rubygems_gem_installer.rb
181181
bundler/lib/bundler/rubygems_integration.rb
182182
bundler/lib/bundler/runtime.rb
183+
bundler/lib/bundler/safe_marshal.rb
183184
bundler/lib/bundler/self_manager.rb
184185
bundler/lib/bundler/settings.rb
185186
bundler/lib/bundler/settings/validator.rb

bundler/lib/bundler.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ module Bundler
3939
environment_preserver.replace_with_backup
4040
SUDO_MUTEX = Thread::Mutex.new
4141

42-
SAFE_MARSHAL_CLASSES = [Symbol, TrueClass, String, Array, Hash, Gem::Version, Gem::Specification].freeze
43-
SAFE_MARSHAL_ERROR = "Unexpected class %s present in marshaled data. Only %s are allowed."
44-
SAFE_MARSHAL_PROC = proc do |object|
45-
object.tap do
46-
unless SAFE_MARSHAL_CLASSES.include?(object.class)
47-
raise TypeError, format(SAFE_MARSHAL_ERROR, object.class, SAFE_MARSHAL_CLASSES.join(", "))
48-
end
49-
end
50-
end
51-
5242
autoload :Definition, File.expand_path("bundler/definition", __dir__)
5343
autoload :Dependency, File.expand_path("bundler/dependency", __dir__)
5444
autoload :Deprecate, File.expand_path("bundler/deprecate", __dir__)
@@ -86,6 +76,7 @@ module Bundler
8676
autoload :UI, File.expand_path("bundler/ui", __dir__)
8777
autoload :URICredentialsFilter, File.expand_path("bundler/uri_credentials_filter", __dir__)
8878
autoload :URINormalizer, File.expand_path("bundler/uri_normalizer", __dir__)
79+
autoload :SafeMarshal, File.expand_path("bundler/safe_marshal", __dir__)
8980

9081
class << self
9182
def configure
@@ -523,7 +514,7 @@ def read_file(file)
523514
end
524515

525516
def safe_load_marshal(data)
526-
load_marshal(data, :marshal_proc => SAFE_MARSHAL_PROC)
517+
load_marshal(data, :marshal_proc => SafeMarshal.proc)
527518
end
528519

529520
def load_gemspec(file, validate = false)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
module Bundler
4+
module SafeMarshal
5+
ALLOWED_CLASSES = [
6+
Array,
7+
FalseClass,
8+
Gem::Specification,
9+
Gem::Version,
10+
Hash,
11+
String,
12+
Symbol,
13+
Time,
14+
TrueClass,
15+
].freeze
16+
17+
ERROR = "Unexpected class %s present in marshaled data. Only %s are allowed."
18+
19+
PROC = proc do |object|
20+
object.tap do
21+
unless ALLOWED_CLASSES.include?(object.class)
22+
raise TypeError, format(ERROR, object.class, ALLOWED_CLASSES.join(", "))
23+
end
24+
end
25+
end
26+
27+
def self.proc
28+
PROC
29+
end
30+
end
31+
end

bundler/spec/bundler/bundler_spec.rb

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,42 @@
2828
expect(Bundler.safe_load_marshal(data)).to eq(simple_structure)
2929
end
3030

31-
it "loads Gem::Version" do
32-
gem_version = Gem::Version.new("3.7.2")
33-
data = Marshal.dump(gem_version)
34-
expect(Bundler.safe_load_marshal(data)).to eq(gem_version)
35-
end
36-
3731
it "loads Gem::Specification" do
38-
gem_spec = Gem::Specification.new("name", "3.7.2")
32+
gem_spec = Gem::Specification.new do |s|
33+
s.name = "bundler"
34+
s.version = Gem::Version.new("2.4.7")
35+
s.installed_by_version = Gem::Version.new("0")
36+
s.authors = ["André Arko",
37+
"Samuel Giddins",
38+
"Colby Swandale",
39+
"Hiroshi Shibata",
40+
"David Rodríguez",
41+
"Grey Baker",
42+
"Stephanie Morillo",
43+
"Chris Morris",
44+
"James Wen",
45+
"Tim Moore",
46+
"André Medeiros",
47+
"Jessica Lynn Suttles",
48+
"Terence Lee",
49+
"Carl Lerche",
50+
"Yehuda Katz"]
51+
s.date = Time.utc(2023, 2, 15)
52+
s.description = "Bundler manages an application's dependencies through its entire life, across many machines, systematically and repeatably"
53+
s.email = ["[email protected]"]
54+
s.homepage = "https://bundler.io"
55+
s.metadata = { "bug_tracker_uri" => "https://github.com/rubygems/rubygems/issues?q=is%3Aopen+is%3Aissue+label%3ABundler",
56+
"changelog_uri" => "https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md",
57+
"homepage_uri" => "https://bundler.io/",
58+
"source_code_uri" => "https://github.com/rubygems/rubygems/tree/master/bundler" }
59+
s.require_paths = ["lib"]
60+
s.required_ruby_version = Gem::Requirement.new([">= 2.6.0"])
61+
s.required_rubygems_version = Gem::Requirement.new([">= 3.0.1"])
62+
s.rubygems_version = "3.4.7"
63+
s.specification_version = 4
64+
s.summary = "The best way to manage your application's dependencies"
65+
s.license = false
66+
end
3967
data = Marshal.dump(gem_spec)
4068
expect(Bundler.safe_load_marshal(data)).to eq(gem_spec)
4169
end

0 commit comments

Comments
 (0)