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 {
97
97
fn read_to_string ( fs : & VendoredFileSystem , path : & VendoredPath ) -> Result < String > {
98
98
let mut archive = fs. lock_archive ( ) ;
99
99
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
+ ) ;
101
110
zip_file. read_to_string ( & mut buffer) ?;
102
111
Ok ( buffer)
103
112
}
You can’t perform that action at this time.
0 commit comments