From 170ffb496b235a0bd485786ab3ae6e8f139ab7c2 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 21 Aug 2024 14:44:16 +0200 Subject: [PATCH] Add comment --- crates/ruff_db/src/vendored.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ruff_db/src/vendored.rs b/crates/ruff_db/src/vendored.rs index 300409ebe326b..d72195aa7ffe4 100644 --- a/crates/ruff_db/src/vendored.rs +++ b/crates/ruff_db/src/vendored.rs @@ -98,6 +98,10 @@ impl VendoredFileSystem { let mut archive = fs.lock_archive(); let mut zip_file = archive.lookup_path(&NormalizedVendoredPath::from(path))?; + // Pre-allocate the buffer with the size specified in the ZIP file metadata + // because `read_to_string` passes `None` as the size hint. + // But let's not trust the zip file metadata (even though it's vendored) + // and limit it to a reasonable size. let mut buffer = String::with_capacity( usize::try_from(zip_file.size()) .unwrap_or(usize::MAX)