Skip to content

Commit

Permalink
add a max depth of 100 to jar recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
spatten committed Oct 31, 2024
1 parent f14db0f commit 1a1fb1d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions extlib/millhone/src/cmd/analyze_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn jars_in_layer(entry: Entry<'_, impl Read>) -> Result<Vec<DiscoveredJar>> {
Err(e) => warn!("failed to fingerprint: {e:?}"),
}
let mut discovered_in_jars =
recursive_jars_in_jars(&entry, path).context("recursively discover jars")?;
recursive_jars_in_jars(&entry, path, 0).context("recursively discover jars")?;
discoveries.append(&mut discovered_in_jars);

Ok(())
Expand All @@ -142,11 +142,17 @@ fn jars_in_layer(entry: Entry<'_, impl Read>) -> Result<Vec<DiscoveredJar>> {
Ok(discoveries)
}

const MAX_JAR_DEPTH: u32 = 100;

#[tracing::instrument(skip(jar_contents))]
fn recursive_jars_in_jars(
jar_contents: &[u8],
containing_jar_path: PathBuf,
depth: u32,
) -> Result<Vec<DiscoveredJar>> {
if depth > MAX_JAR_DEPTH {
return Ok(vec![]);
}
let mut discoveries = Vec::new();
let mut archive =
zip::ZipArchive::new(std::io::Cursor::new(jar_contents)).context("unzipping jar")?;
Expand Down Expand Up @@ -180,8 +186,8 @@ fn recursive_jars_in_jars(
}

// recursively find more jars
let mut discovered_in_jars =
recursive_jars_in_jars(&buffer, joined_path).context("recursively discover jars")?;
let mut discovered_in_jars = recursive_jars_in_jars(&buffer, joined_path, depth + 1)
.context("recursively discover jars")?;
discoveries.append(&mut discovered_in_jars);
}
Ok(discoveries)
Expand Down

0 comments on commit 1a1fb1d

Please sign in to comment.