# phar_tar_writeheaders_int() buffer overflow

phar_tar_writeheaders_int() used strncpy with entry->link length into a 100-byte header->linkname field, overflowing the tar header struct on long link values.

- Payout: $1,500
- Severity: high
- Program: Internet Bug Bounty
- Found by: jordyzomer
- Disclosed: 2020-11-09
- CVE: CVE-2019-9675
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/504761
- Library page: https://bugbountylibrary.com/r/h1%3A504761
- Tags: area:oss domain:oss impact:dos impact:rce kind:bounty platform:hackerone sev:high tech:php technique:source-review vuln:memory-corruption

**Target:** PHP ext/phar tar header writer (phar_tar_writeheaders_int)
**Root cause:** strncpy(header.linkname, entry->link, strlen(entry->link)) copies attacker-controlled length into a fixed 100-byte char array, overflowing _tar_header when link exceeds 100 bytes.
**Steps:**
1. Craft a phar archive whose tar entry has a link field longer than 100 bytes
2. Trigger phar_tar_writeheaders_int() to write the tar header for that entry
3. strncpy copies strlen(entry->link) bytes into header->linkname (100 bytes), overflowing adjacent struct fields
**How found:** Code reading of ext/phar/tar.h and the writeheaders function: noticed strncpy size argument used entry->link length rather than sizeof(header->linkname), a classic fixed-buffer mismatch.
**Insight:** When auditing C code, grep for strncpy/strcpy/memcpy where the size argument derives from the source length rather than the destination buffer size; struct field definitions in headers reveal the true bound.

