Commit 15c6484
committed
file/archive_file_zlib: guard ZIP context allocation
zip_parse_file_init() reads the central-directory size and offset
from the ZIP footer and allocates "sizeof(zip_context_t) +
directory_size" bytes for the context + directory. Three issues:
1. 32-bit allocation wraparound. On 32-bit hosts (3DS, Vita, PSP,
Wii, Wii U) size_t is 32 bits, so a crafted directory_size near
UINT32_MAX makes the "+ sizeof(zip_context_t)" wrap to a tiny
value. The subsequent directory_end = directory + directory_size
computation then points roughly 4 GiB past a small allocation,
and every read from the directory is out of bounds.
2. Unchecked malloc return. Even on 64-bit, a 4 GiB directory_size
request from a crafted ZIP can fail allocation; the next line
dereferences the returned NULL unconditionally.
3. Incomplete sanity check. The existing check only verifies that
directory_size and directory_offset individually fit within the
archive. With offset = archive_size - 1 and size = archive_size,
each passes but the combination claims the directory runs past
EOF. The subsequent short read is caught, but only after the
large bogus allocation is already made.
Fix: reject the combined "offset + size > archive_size", reject
sizes that would overflow the allocation, and check the malloc
return.1 parent 1235db3 commit 15c6484
1 file changed
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
511 | 526 | | |
512 | 527 | | |
513 | 528 | | |
514 | 529 | | |
| 530 | + | |
| 531 | + | |
515 | 532 | | |
516 | 533 | | |
517 | 534 | | |
| |||
0 commit comments