Skip to content
Memory corruption Disclosed report Advanced CVE-2019-9675

phar_tar_writeheaders_int() buffer overflow

A buffer overflow exists in the phar_tar_writeheaders_int() function because it copies entry->link into a fixed-size 100-byte field without checking length. An attacker could overflow the buffer, potentially causing a crash, elevation of privilege, or remote code execution.

jordyzomer Follow

Originally disclosed on HackerOne

Bounty$1,500 High 8.1 View original
  • Triaged in 2 months
  • Fixed in 19 months
  • Paid in 19 months
  • Disclosed after 20 months

A buffer overflow has been found in the phar_tar_writeheaders_int() function.

it does a strncpy to header->linkname from entry->link with the size of entry->link.

As you can see in https://github.com/php/php-src/blob/master/ext/phar/tar.h#L66 , header->linkname is a char of the size 100. Once entry->link contains a value that's bigger than 100 it will overflow the _tar_header structure.

This can be fixed by setting the size argument of strncpy to sizeof(header->linkname) for example:

strncpy(header.linkname, entry->link, strlen(header->linkname);

This has been fixed in the following references:

https://github.com/php/php-src/commit/071e18c6971c4cf64297378b30b945a1b85d682a http://git.php.net/?p=php-src.git;a=commit;h=e0f5d62bd6690169998474b62f92a8c5ddf0e699 https://bugs.php.net/bug.php?id=77586&edit=2

Kind Regards,

Jordy Zomer

Impact

An attacker could overflow the buffer resulting in either a crash (DoS), EOP or RCE.

The original report as published on HackerOne, by jordyzomer. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code uses strncpy with the length of the source string instead of the destination buffer size, so a long entry->link overflows the 100-byte header->linkname field.

Impact

An attacker could overflow the buffer resulting in either a crash (DoS), EOP or RCE.

What the attacker needed

Ability to supply a crafted tar entry with a long link name

The fix

The size argument of strncpy should be set to the size of the destination buffer (header->linkname) instead of the source length; the report states this has been fixed in referenced commits.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A buffer overflow happens when a program writes more data into a fixed-size memory area than it can hold, spilling into adjacent memory. Here, a filename field in a tar archive header is only 100 bytes, but the code copies a longer value without limiting the length. This can crash the program or let an attacker run their own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by jordyzomer

View all

2 more disclosed reports, best first.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.