Commit 1235db3
committed
file/archive_file_zlib: harden ZIP central-directory parser
Two related issues in the ZIP central-directory walker and filename
callback, both reachable from any ZIP load (ROM scan, content load,
extract-to-dir, etc):
1. zip_parse_file_iterate_step_internal() checked only that the
directory entry pointer fell inside the directory block, not that
a full 46-byte central-file-header plus the variable-length name,
extra and comment fields actually fit. A malformed archive with a
truncated trailing entry caused read_le() to read past the
allocation. Reproduced under AddressSanitizer with a 40-byte
directory:
ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 1 at 2 bytes after 40-byte region
Fix by checking the available entry size (a) before the header
reads, and (b) before the memcpy of the filename, against the
declared namelength/extralength/commentlength.
2. zip_file_decompressed() computed "name[strlen(name) - 1]" without
guarding against an empty filename entry. When strlen == 0 the
index wraps to SIZE_MAX and the dereference reads far out of
bounds. A ZIP central directory is allowed to contain zero-length
name entries only if malformed, but producing such an archive is
trivial.
Both fixes reject the malformed entry and continue, so the parser
skips bad archives rather than crashing.1 parent 1d9ed2e commit 1235db3
1 file changed
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
362 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
363 | 370 | | |
364 | 371 | | |
365 | 372 | | |
| |||
538 | 545 | | |
539 | 546 | | |
540 | 547 | | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
541 | 554 | | |
542 | 555 | | |
543 | 556 | | |
| |||
555 | 568 | | |
556 | 569 | | |
557 | 570 | | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
558 | 578 | | |
559 | 579 | | |
560 | 580 | | |
| |||
0 commit comments