phacility/phabricator · error · Exception

Unable to determine image width and height with…

Error message

Unable to determine image width and height with getimagesize().

What it means

getimagesize() succeeded (returned an array) but reported a width or height of zero or less. This is a malformed-image edge case: the header parsed far enough to produce dimensions, but the dimensions themselves are degenerate, so the transform pipeline refuses to continue. It is a data-integrity failure of the uploaded file, distinct from the getimagesize()-returned-false case.

Solutions

  1. Re-encode or replace the file with one from a known-good tool (open and re-save it in an image editor).
  2. Add server-side validation that rejects uploads where getimagesize() yields non-positive dimensions.
  3. Catch the exception at transform time and skip transforms for such files.

Example fix

// validation before accepting/transforming an upload
$info = @getimagesize($tmp_path);
if ($info === false || $info[0] <= 0 || $info[1] <= 0) {
  throw new Exception('Uploaded file is not a valid image.');
}
Defensive patterns

Strategy: validation

Validate before calling

$info = @getimagesize($tmp_path);
if ($info === false || $info[0] <= 0 || $info[1] <= 0) {
  return null; // degenerate dimensions; treat as invalid image
}

Type guard

function hasPositiveImageDimensions($info): bool {
  return is_array($info) && (int)$info[0] > 0 && (int)$info[1] > 0;
}

Prevention

When it happens

Trigger: Transforming a crafted or damaged image whose header encodes width/height <= 0 — e.g. hand-edited or bit-flipped files, images produced by broken encoders, or fuzzed payloads that pass format sniffing but carry nonsense dimensions.

Common situations: Malformed files that evade naive client-side validation; encoder bugs in whatever generated the upload; almost never produced by mainstream image software, so treat the file as bad data.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/ec73824789c32d96. Report an issue: GitHub.

Appendix: source

Thrown at src/applications/files/transform/PhabricatorFileImageTransform.php:328

    $tmp_path = (string)$tmp;

    $trap = new PhutilErrorTrap();
    $info = @getimagesize($tmp_path);
    $errors = $trap->getErrorsAsString();
    $trap->destroy();

    unset($tmp);

    if ($info === false) {
      throw new Exception(
        pht(
          'Unable to get image information with getimagesize(): %s',
          $errors));
    }

    list($width, $height) = $info;
    if (($width <= 0) || ($height <= 0)) {
      throw new Exception(
        pht(
          'Unable to determine image width and height with getimagesize().'));
    }

    $max_pixels = (4096 * 4096);
    $img_pixels = ($width * $height);

    if ($img_pixels > $max_pixels) {
      throw new Exception(
        pht(
          'This image (with dimensions %spx x %spx) is too large to '.
          'transform. The image has %s pixels, but transforms are limited '.
          'to images with %s or fewer pixels.',
          new PhutilNumber($width),
          new PhutilNumber($height),
          new PhutilNumber($img_pixels),
          new PhutilNumber($max_pixels)));
    }

View on GitHub (pinned to 5720a38cfe)