File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,16 @@ impl VendoredFileSystem {
9797 fn read_to_string ( fs : & VendoredFileSystem , path : & VendoredPath ) -> Result < String > {
9898 let mut archive = fs. lock_archive ( ) ;
9999 let mut zip_file = archive. lookup_path ( & NormalizedVendoredPath :: from ( path) ) ?;
100- let mut buffer = String :: new ( ) ;
100+
101+ // Pre-allocate the buffer with the size specified in the ZIP file metadata
102+ // because `read_to_string` passes `None` as the size hint.
103+ // But let's not trust the zip file metadata (even though it's vendored)
104+ // and limit it to a reasonable size.
105+ let mut buffer = String :: with_capacity (
106+ usize:: try_from ( zip_file. size ( ) )
107+ . unwrap_or ( usize:: MAX )
108+ . min ( 10_000_000 ) ,
109+ ) ;
101110 zip_file. read_to_string ( & mut buffer) ?;
102111 Ok ( buffer)
103112 }
You can’t perform that action at this time.
0 commit comments