Skip to content

Fix GH-25964: WebP VP8/VP8L dimensions accepted with an invalid signature - #25983

Open
lazerg wants to merge 2 commits into
php:masterfrom
lazerg:fix/gh-25964
Open

lazerg wants to merge 2 commits into
php:masterfrom
lazerg:fix/gh-25964

Conversation

@lazerg

@lazerg lazerg commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

A lossy VP8 key frame starts with the 9D 01 2A start code, but php_handle_webp() read the width and height from bytes 14-17 without checking it. Any VP8 chunk was accepted and arbitrary bytes were returned as dimensions. The start code is now checked, and getimagesize() returns false when it does not match.

Fixes #25964

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as GH-25985: this changes what getimagesize() returns for an invalid header that has been accepted for years, with no crash or memory issue behind it, so please retarget to master.

Comment thread ext/standard/image.c

switch (format) {
case ' ':
if (buf[11] != 0x9d || buf[12] != 0x01 || buf[13] != 0x2a) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VP8L below has the same gap: the chunk must start with the 0x2F signature byte at buf[8], which isn't checked. With this patch, a VP8L chunk whose signature byte is 0x00 still returns width 16384. Please check it too and add that case to the test.

@lazerg
lazerg changed the base branch from PHP-8.4 to master December 1, 2026 12:56
@lazerg lazerg changed the title Fix GH-25964: WebP VP8 dimensions accepted with an invalid start code Fix GH-25964: WebP VP8/VP8L dimensions accepted with an invalid signature Dec 1, 2026
@lazerg

lazerg commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Retargeted to master. I also added the VP8L 0x2F signature check at buf[8], with a test case for it.

Comment thread ext/standard/tests/image/gh25964.phpt Outdated
var_dump(getimagesizefromstring($webp));

$webp = 'RIFF' . pack('V', 17) . 'WEBP'
. 'VP8L' . pack('V', 5)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chunk is too short to reach the new check: php_handle_webp() returns NULL when it can't read 18 bytes, so this case is false without the fix too. Padding it to 10 bytes ('VP8L' . pack('V', 10) plus five more \x00, RIFF size 22) makes it fail before the fix (width 16384) and pass after.

@lazerg

lazerg commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Padded the VP8L chunk to 10 bytes so the test reaches the signature check, pushed. The two red jobs failed in the apt and Windows build steps before any tests ran, so they don't look related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getimagesize(): WebP VP8 dimensions are accepted with an invalid start code

2 participants