Unbounded Zip-Entry Inflation in classgraph-vfs
Description
I was reading FastZipEntry.load()/open() in classgraph-vfs and noticed neither one enforces any decompression budget, so a single ordinary zip entry can be a classic zip bomb and take down the scanning JVM's heap. What makes it worth flagging is that classgraph already ships exactly this kind of budget for nested-jar entries, just not for ordinary ones read through the public API.
Details
// classgraph-vfs/src/main/java/io/github/classgraph/vfs/internal/zip/FastZipEntry.java:356-375
public byte[] load() throws IOException {
if (!isDeflated) {
return getRawSlice().load();
}
var inflatedSizeHint = inflatedSizeHint();
...
// Slice.readAllBytesAsArray closes the stream -- no budget, reads to EOF
return Slice.readAllBytesAsArray(open(), inflatedSizeHint);
}inflatedSizeHint() just sizes a buffer; it's never checked as a refusal threshold. Compare that to the sibling nested-jar path:
// classgraph-vfs/src/main/java/io/github/classgraph/vfs/internal/zip/NestedJarInflationAllowance.java:36-46
final class NestedJarInflationAllowance {
static final long MAX_INFLATION_RATIO = 100L;
static final long MIN_MAX_BYTES = 256L * 1024 * 1024;allowance.limit(...) wraps the exact same open() stream, but only when LogicalZipFile.openNestedJar() is materializing a nested jarfile. Every ordinary entry reached via Resource.load()/.open()/.getContentAsString() goes through the identical inflate call with no wrapper at all, same primitive, no guard, a classic asymmetric-budget mistake.
Proof of concept
OpenJDK 25.0.2, classgraph 6.0.2, run with -Xmx256m so the amplification shows up fast and deterministically. I built a jar with one entry of zero bytes, deflated to maximum ratio:
writeZeroFilledDeflatedEntry(bombJar, "big.bin", 512L * 1024 * 1024); // ~512 MiB inflated
try (ScanResult sr = new ClassGraph()
.enableClasspathEntries(bombJar.getAbsolutePath())
.acceptPaths("/")
.scan()) {
for (final Resource res : sr.getAllResources()) {
final byte[] b = res.load(); // <-- no budget
}
}As a control, I put the identical-size payload where classgraph treats it as a nested jarfile instead (LogicalZipFile.openNestedJar()), the one path that is budgeted, and ran it with .verbose().
Result
Main run: OutOfMemoryError straight out of the public API, a few hundred KB on disk driving the heap to exhaustion:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at io.github.classgraph.vfs.internal.slice.Slice.readAllBytesAsArray(Slice.java:432)
at io.github.classgraph.vfs.internal.zip.FastZipEntry.load(FastZipEntry.java:374)
at io.github.classgraph.Resource.load(Resource.java:493)
at poc.ZipBomb02Poc.runMain(ZipBomb02Poc.java:59)Control run, identical payload size, budgeted path: IOException: ... would inflate to more than 268435456 bytes in all, which is the larger of 100 times its length and 256 MiB, 0 bytes loaded. Same bytes, same classgraph version — the only variable is which of classgraph's own two code paths processes the entry, which isolates the missing budget as the cause.
Impact
Anyone whose application scans classpath entries sourced from a less-trusted party — a plugin author, an uploaded artifact — can crash the scanning JVM's process with one crafted jar, no credentials or user interaction needed. This is not remote code execution and it does not read or modify any data; it's a denial-of-service against the scanning process itself, and it is cross-principal in that the attacker only has to supply a jar the victim later scans.
Suggested Fix
Give PhysicalZipFile a per-toplevel allowance the same way it already owns nestedJarInflationAllowance, and wrap FastZipEntry.open()'s stream with it:
final var allowance = physicalZipFile.ordinaryEntryInflationAllowance; // new, same shape as nestedJarInflationAllowance
return Slice.readAllBytesAsArray(allowance.limit(open(), entryName), inflatedSizeHint);