Commit a5df149
pe: fix three PE resource parsing issues (#490)
* fix: Resolve three critical security vulnerabilities in PE resource parsing
This commit addresses three security vulnerabilities that could cause denial
of service attacks through crafted PE files:
1. Index out of bounds in UTF-16 string parsing (resource.rs:52)
- Added bounds checking before accessing chunk elements
- Prevents panic when processing odd-length byte arrays
2. Integer overflow in resource directory entry count (resource.rs:172)
- Replaced addition with saturating_add to prevent overflow
- Handles cases where entry counts exceed u16::MAX
3. Stack overflow in recursive resource directory parsing (resource.rs:393)
- Added maximum recursion depth limit of 10 levels
- Prevents infinite recursion through circular references
- Limit based on typical PE resource structure (3-4 levels: Type → Name/ID → Language → Data)
All fixes maintain backward compatibility while ensuring robust error
handling for malformed PE files. Tested with proof-of-concept files
that previously triggered crashes.
Fixes: Index out of bounds, integer overflow, and stack overflow vulnerabilities
---------
Co-authored-by: rcampbell_halcyon <[email protected]>1 parent 69dba8b commit a5df149
1 file changed
+23
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
| 173 | + | |
173 | 174 | | |
174 | 175 | | |
175 | 176 | | |
| |||
366 | 367 | | |
367 | 368 | | |
368 | 369 | | |
369 | | - | |
| 370 | + | |
370 | 371 | | |
371 | 372 | | |
372 | 373 | | |
| |||
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
380 | | - | |
| 381 | + | |
381 | 382 | | |
382 | 383 | | |
383 | 384 | | |
| |||
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
389 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
390 | 404 | | |
391 | | - | |
392 | | - | |
393 | | - | |
| 405 | + | |
394 | 406 | | |
395 | | - | |
396 | | - | |
| 407 | + | |
397 | 408 | | |
| 409 | + | |
| 410 | + | |
398 | 411 | | |
399 | 412 | | |
400 | 413 | | |
| |||
0 commit comments