Heap out-of-bounds write in libarchive ZIP writer on long pathnames
Key facts
- Attack vector
- Local
- Privileges required
- None
- User interaction
- Required
- Attack complexity
- High
- Impact type
- —
- Confidentiality · integrity · availability
- None · None · None
- Fix status
- Fixed
Attack profile from CVSS 3.1 · GHSA-xgqq-r5j8-3mch. Fix status from GitHub.
Summary
libarchive up to and including 3.8.7 contains a heap out-of-bounds write (CWE-787) in its ZIP writer. When an archive entry pathname longer than 65536 bytes is written to a central directory segment, the copy runs past the allocated heap buffer. An attacker can supply a crafted archive with an oversized pathname that an application re-packs as ZIP, which requires user interaction and high attack complexity. The source reports memory corruption only and does not demonstrate code execution.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
I found a heap out-of-bounds write in the ZIP writer while testing oversized pathname handling. The issue is in `libarchive/archive_write_set_format_zip.c`. In `zip_write_file_header()`, the code calculates `filename_length` from the archive entry pathname, calls `cd_alloc(zip, filename_length)`, and then copies the full pathname into the returned buffer with `copy_path()`. The problem is that `cd_alloc()` always allocates a fixed 64 KiB segment: ```c segment->buff_size = 64 * 1024; segment->buff = malloc(segment->buff_size); ``` but later advances the write pointer by the requested `length`: ```c p = zip->central_directory_last->p; zip->central_directory_last->p += length; ``` Then `copy_path()` copies the full pathname length: ```c pathlen = strlen(path); memcpy(p, path, pathlen); ``` So if `filename_length > 65536`, the writer copies more data than fits in the allocated central-directory segment. ## Reachability This is reachable from attacker-controlled input if an application reads an archive entry with a very long pathname and then re-packs it as ZIP. One simple example is: ```sh bsdtar --format=zip -cf out.zip @evil.tar ``` The tar reader accepts long PAX path values, so a crafted PAX tar can carry the oversized pathname into the ZIP writer. ## Reproduction I reproduced this locally on: - released `v3.8.7` (tag `cf3debc3`) - current master / `3.9.0dev` (commit `aca8b0d3`) I used a PAX tar containing one file with a 131072-byte pathname, then converted it to ZIP with an ASAN build of `bsdtar`. The invocation was: ```bash bsdtar --format=zip -cf libarchive-zip-pathname-oob-write.zip @libarchive-zip-pathname-oob-write.tar ``` ASAN reported: ```bash ==2025920==ERROR: AddressSanitizer: heap-buffer-overflow WRITE of size 131072 at 0x53100004c800 thread T0 #0 0x... in memcpy #1 0x... in copy_path ``` The process then aborted with return code `-6`. I also checked the exact boundary on an ASAN build of released `v3.8.7`: - pathname length `65536`: ZIP creation completed successfully, return code `0`, and there was no ASAN finding - pathname length `65537`: immediate `AddressSanitizer: heap-buffer-overflow`, `WRITE of size 65537`, followed by `SIGABRT` This matches the source-level condition: the central-directory segment is 65536 bytes, and the overflow begins when `filename_length` exceeds that size. ## Impact This is a confirmed heap out-of-bounds write in the libarchive ZIP writer reachable from crafted archive input that is later converted to ZIP. I am using `bsdtar` here as a simple reproducer, but the bug is in the library code in `archive_write_set_format_zip.c`, not in a `bsdtar`-specific wrapper. I am only claiming memory corruption here. I have not attempted to demonstrate code execution. ## Suggested fix I think there are two reasonable fixes here: 1. reject pathnames that exceed the ZIP writer's supported filename length before calling `cd_alloc()` / `copy_path()` 2. make `cd_alloc()` allocate enough space for the requested length instead of always returning a 64 KiB segment
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| — | libarchive | <= 3.8.7 | >= 3.8.8 | Patch available | GHSA-xgqq-r5j8-3mch |
- libarchive Vendor— Affected <= 3.8.7 Fixed in >= 3.8.8 Patch available GHSA-xgqq-r5j8-3mch
Remediation
Upgrade libarchive to version 3.8.8 or later, which is the fixed version listed for this product.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-xgqq-r5j8-3mch libarchive Fixed in >= 3.8.8 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-xgqq-r5j8-3mch
- 2026-11-12 Alias added: CVE-2026-45308
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences