|
| 1 | +From 6a35becc9ac9f4b27b1d5b5b1fb8cf7aa9b49d5d Mon Sep 17 00:00:00 2001 |
| 2 | +From: Hiroshi SHIBATA < [email protected]> |
| 3 | +Date: Tue, 20 Feb 2024 17:30:25 +0900 |
| 4 | +Subject: [PATCH] Filter marshaled objects |
| 5 | + |
| 6 | +--- |
| 7 | + lib/rdoc/store.rb | 45 ++++++++++++++++++++++++++------------------- |
| 8 | + 1 file changed, 26 insertions(+), 19 deletions(-) |
| 9 | + |
| 10 | +diff --git a/lib/rdoc/store.rb b/lib/rdoc/store.rb |
| 11 | +index 5ba671ca1b..5b663d73fb 100644 |
| 12 | +--- a/lib/rdoc/store.rb |
| 13 | ++++ b/lib/rdoc/store.rb |
| 14 | +@@ -556,9 +556,7 @@ def load_all |
| 15 | + def load_cache |
| 16 | + #orig_enc = @encoding |
| 17 | + |
| 18 | +- File.open cache_path, 'rb' do |io| |
| 19 | +- @cache = Marshal.load io.read |
| 20 | +- end |
| 21 | ++ @cache = marshal_load(cache_path) |
| 22 | + |
| 23 | + load_enc = @cache[:encoding] |
| 24 | + |
| 25 | +@@ -615,9 +613,7 @@ def load_class klass_name |
| 26 | + def load_class_data klass_name |
| 27 | + file = class_file klass_name |
| 28 | + |
| 29 | +- File.open file, 'rb' do |io| |
| 30 | +- Marshal.load io.read |
| 31 | +- end |
| 32 | ++ marshal_load(file) |
| 33 | + rescue Errno::ENOENT => e |
| 34 | + error = MissingFileError.new(self, file, klass_name) |
| 35 | + error.set_backtrace e.backtrace |
| 36 | +@@ -630,14 +626,10 @@ def load_class_data klass_name |
| 37 | + def load_method klass_name, method_name |
| 38 | + file = method_file klass_name, method_name |
| 39 | + |
| 40 | +- File.open file, 'rb' do |io| |
| 41 | +- obj = Marshal.load io.read |
| 42 | +- obj.store = self |
| 43 | +- obj.parent = |
| 44 | +- find_class_or_module(klass_name) || load_class(klass_name) unless |
| 45 | +- obj.parent |
| 46 | +- obj |
| 47 | +- end |
| 48 | ++ obj = marshal_load(file) |
| 49 | ++ obj.store = self |
| 50 | ++ obj.parent ||= find_class_or_module(klass_name) || load_class(klass_name) |
| 51 | ++ obj |
| 52 | + rescue Errno::ENOENT => e |
| 53 | + error = MissingFileError.new(self, file, klass_name + method_name) |
| 54 | + error.set_backtrace e.backtrace |
| 55 | +@@ -650,11 +642,9 @@ def load_method klass_name, method_name |
| 56 | + def load_page page_name |
| 57 | + file = page_file page_name |
| 58 | + |
| 59 | +- File.open file, 'rb' do |io| |
| 60 | +- obj = Marshal.load io.read |
| 61 | +- obj.store = self |
| 62 | +- obj |
| 63 | +- end |
| 64 | ++ obj = marshal_load(file) |
| 65 | ++ obj.store = self |
| 66 | ++ obj |
| 67 | + rescue Errno::ENOENT => e |
| 68 | + error = MissingFileError.new(self, file, page_name) |
| 69 | + error.set_backtrace e.backtrace |
| 70 | +@@ -976,4 +966,21 @@ def unique_modules |
| 71 | + @unique_modules |
| 72 | + end |
| 73 | + |
| 74 | ++ private |
| 75 | ++ def marshal_load(file) |
| 76 | ++ File.open(file, 'rb') {|io| Marshal.load(io, MarshalFilter)} |
| 77 | ++ end |
| 78 | ++ |
| 79 | ++ MarshalFilter = proc do |obj| |
| 80 | ++ case obj |
| 81 | ++ when true, false, nil, Array, Class, Encoding, Hash, Integer, String, Symbol, RDoc::Text |
| 82 | ++ else |
| 83 | ++ unless obj.class.name.start_with("RDoc::") |
| 84 | ++ raise TypeError, "not permitted class: #{obj.class.name}" |
| 85 | ++ end |
| 86 | ++ end |
| 87 | ++ obj |
| 88 | ++ end |
| 89 | ++ private_constant :MarshalFilter |
| 90 | ++ |
| 91 | + end |
| 92 | +-- |
| 93 | +2.43.2 |
| 94 | + |
0 commit comments