@@ -556,9 +556,7 @@ def load_all
556
556
def load_cache
557
557
#orig_enc = @encoding
558
558
559
- File . open cache_path , 'rb' do |io |
560
- @cache = Marshal . load io . read
561
- end
559
+ @cache = marshal_load ( cache_path )
562
560
563
561
load_enc = @cache [ :encoding ]
564
562
@@ -615,9 +613,7 @@ def load_class klass_name
615
613
def load_class_data klass_name
616
614
file = class_file klass_name
617
615
618
- File . open file , 'rb' do |io |
619
- Marshal . load io . read
620
- end
616
+ marshal_load ( file )
621
617
rescue Errno ::ENOENT => e
622
618
error = MissingFileError . new ( self , file , klass_name )
623
619
error . set_backtrace e . backtrace
@@ -630,14 +626,10 @@ def load_class_data klass_name
630
626
def load_method klass_name , method_name
631
627
file = method_file klass_name , method_name
632
628
633
- File . open file , 'rb' do |io |
634
- obj = Marshal . load io . read
635
- obj . store = self
636
- obj . parent =
637
- find_class_or_module ( klass_name ) || load_class ( klass_name ) unless
638
- obj . parent
639
- obj
640
- end
629
+ obj = marshal_load ( file )
630
+ obj . store = self
631
+ obj . parent ||= find_class_or_module ( klass_name ) || load_class ( klass_name )
632
+ obj
641
633
rescue Errno ::ENOENT => e
642
634
error = MissingFileError . new ( self , file , klass_name + method_name )
643
635
error . set_backtrace e . backtrace
@@ -650,11 +642,9 @@ def load_method klass_name, method_name
650
642
def load_page page_name
651
643
file = page_file page_name
652
644
653
- File . open file , 'rb' do |io |
654
- obj = Marshal . load io . read
655
- obj . store = self
656
- obj
657
- end
645
+ obj = marshal_load ( file )
646
+ obj . store = self
647
+ obj
658
648
rescue Errno ::ENOENT => e
659
649
error = MissingFileError . new ( self , file , page_name )
660
650
error . set_backtrace e . backtrace
@@ -976,4 +966,21 @@ def unique_modules
976
966
@unique_modules
977
967
end
978
968
969
+ private
970
+ def marshal_load ( file )
971
+ File . open ( file , 'rb' ) { |io | Marshal . load ( io , MarshalFilter ) }
972
+ end
973
+
974
+ MarshalFilter = proc do |obj |
975
+ case obj
976
+ when true , false , nil , Array , Class , Encoding , Hash , Integer , String , Symbol , RDoc ::Text
977
+ else
978
+ unless obj . class . name . start_with ( "RDoc::" )
979
+ raise TypeError , "not permitted class: #{ obj . class . name } "
980
+ end
981
+ end
982
+ obj
983
+ end
984
+ private_constant :MarshalFilter
985
+
979
986
end
0 commit comments