We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a35cdbb commit 785c399Copy full SHA for 785c399
crates/ruff_db/src/vendored.rs
@@ -97,7 +97,16 @@ impl VendoredFileSystem {
97
fn read_to_string(fs: &VendoredFileSystem, path: &VendoredPath) -> Result<String> {
98
let mut archive = fs.lock_archive();
99
let mut zip_file = archive.lookup_path(&NormalizedVendoredPath::from(path))?;
100
- let mut buffer = String::new();
+
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
+ );
110
zip_file.read_to_string(&mut buffer)?;
111
Ok(buffer)
112
}
0 commit comments