{"record":{"id":"ec73824789c32d96","repo":"phacility/phabricator","slug":"unable-to-determine-image-width-and-height-with-ge","errorCode":null,"errorMessage":"Unable to determine image width and height with getimagesize().","messagePattern":"Unable to determine image width and height with getimagesize\\(\\)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/files/transform/PhabricatorFileImageTransform.php","lineNumber":328,"sourceCode":"    $tmp_path = (string)$tmp;\n\n    $trap = new PhutilErrorTrap();\n    $info = @getimagesize($tmp_path);\n    $errors = $trap->getErrorsAsString();\n    $trap->destroy();\n\n    unset($tmp);\n\n    if ($info === false) {\n      throw new Exception(\n        pht(\n          'Unable to get image information with getimagesize(): %s',\n          $errors));\n    }\n\n    list($width, $height) = $info;\n    if (($width <= 0) || ($height <= 0)) {\n      throw new Exception(\n        pht(\n          'Unable to determine image width and height with getimagesize().'));\n    }\n\n    $max_pixels = (4096 * 4096);\n    $img_pixels = ($width * $height);\n\n    if ($img_pixels > $max_pixels) {\n      throw new Exception(\n        pht(\n          'This image (with dimensions %spx x %spx) is too large to '.\n          'transform. The image has %s pixels, but transforms are limited '.\n          'to images with %s or fewer pixels.',\n          new PhutilNumber($width),\n          new PhutilNumber($height),\n          new PhutilNumber($img_pixels),\n          new PhutilNumber($max_pixels)));\n    }","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/files/transform/PhabricatorFileImageTransform.php#L310-L346","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-encode or replace the file with one from a known-good tool (open and re-save it in an image editor).","Add server-side validation that rejects uploads where getimagesize() yields non-positive dimensions.","Catch the exception at transform time and skip transforms for such files."],"exampleFix":"// validation before accepting/transforming an upload\n$info = @getimagesize($tmp_path);\nif ($info === false || $info[0] <= 0 || $info[1] <= 0) {\n  throw new Exception('Uploaded file is not a valid image.');\n}","handlingStrategy":"validation","validationCode":"$info = @getimagesize($tmp_path);\nif ($info === false || $info[0] <= 0 || $info[1] <= 0) {\n  return null; // degenerate dimensions; treat as invalid image\n}","typeGuard":"function hasPositiveImageDimensions($info): bool {\n  return is_array($info) && (int)$info[0] > 0 && (int)$info[1] > 0;\n}","tryCatchPattern":null,"preventionTips":["Validate both width and height are >= 1 whenever you accept image uploads.","Treat zero-dimension images as malformed data; do not retry or re-upload them unchanged.","Re-encode suspicious files with a known-good tool before storing."],"tags":["phabricator","image-transform","corrupt-file","dimensions","php"],"backgroundTag":"invalid-image-data","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}