Skip to content

getimagesize(): JPEG 2000 Csiz is accepted without component descriptors #25960

Backlog

Description

@kid-lxy

Description

The following code:

<?php
$jpc = "\xFF\x4F\xFF\x51"
     . pack('nn', 47, 0)
     . pack('NN', 1, 1)
     . str_repeat("\0", 24)
     . pack('n', 3);
var_dump(getimagesizefromstring($jpc));

Resulted in this output:

array(8) {
  [0]=>
  int(1)
  [1]=>
  int(1)
  [2]=>
  int(9)
  [3]=>
  string(20) "width="1" height="1""
  ["channels"]=>
  int(3)
  ["mime"]=>
  string(24) "application/octet-stream"
  ["width_unit"]=>
  string(2) "px"
  ["height_unit"]=>
  string(2) "px"
}

But I expected this output instead:

bool(false)

The JPC parser reads Csiz at ext/standard/image.c:627, then loops over that count at line 635 without requiring 3 * Csiz available descriptor bytes or checking the reads at lines 636-643. Since Csiz = 3 requires nine component-descriptor bytes, this truncated codestream must be rejected instead of returning three channels.

PHP Version

PHP 8.7.0-dev (cli) (built: Nov 29 2026 03:42:09) (NTS)
Copyright © The PHP Group and Contributors
Zend Engine v4.7.0-dev, Copyright © Zend by Perforce
    with Zend OPcache v8.7.0-dev, Copyright ©, by Zend by Perforce

Operating System

Ubuntu 24.04.5 LTS

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions