{"record":{"id":"bb60cf08e605ac9b","repo":"microsoft/playwright","slug":"invalid-input-image","errorCode":null,"errorMessage":"Invalid input image","messagePattern":"Invalid input image","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/isomorphic/imageUtils.ts","lineNumber":52,"sourceCode":"        buffer[to + 1] = 0;\n        buffer[to + 2] = 0;\n        buffer[to + 3] = 0;\n      }\n    }\n  }\n  return { data: Buffer.from(buffer), width: size.width, height: size.height };\n}\n\nexport function scaleImageToSize(image: ImageData, size: { width: number; height: number }): ImageData {\n  const { data: src, width: w1, height: h1 } = image;\n  const w2 = Math.max(1, Math.floor(size.width));\n  const h2 = Math.max(1, Math.floor(size.height));\n\n  if (w1 === w2 && h1 === h2)\n    return image;\n\n  if (w1 <= 0 || h1 <= 0)\n    throw new Error('Invalid input image');\n  if (size.width <= 0 || size.height <= 0 || !isFinite(size.width) || !isFinite(size.height))\n    throw new Error('Invalid output dimensions');\n\n  const clamp = (v: number, lo: number, hi: number) => (v < lo ? lo : v > hi ? hi : v);\n\n  // Catmull–Rom weights\n  const weights = (t: number, o: Float32Array) => {\n    const t2 = t * t;\n    const t3 = t2 * t;\n    o[0] = -0.5 * t + 1.0 * t2 - 0.5 * t3;\n    o[1] = 1.0 - 2.5 * t2 + 1.5 * t3;\n    o[2] = 0.5 * t + 2.0 * t2 - 1.5 * t3;\n    o[3] = -0.5 * t2 + 0.5 * t3;\n  };\n\n  const srcRowStride = w1 * 4;\n  const dstRowStride = w2 * 4;\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/isomorphic/imageUtils.ts#L34-L70","documentation":"scaleImageToSize throws 'Invalid input image' when the source image's width or height is <= 0. The function performs bicubic Catmull-Rom resampling which requires a valid positive-area source; a degenerate source (zero rows or columns) has no pixels to sample.","triggerScenarios":"Calling scaleImageToSize with an ImageData whose width or height is 0 or negative. This typically originates from screenshot/trace-image pipelines that produced an empty buffer (e.g. screenshot of a 0-size element, or a decoded image whose dimensions were not populated).","commonSituations":"Screenshots of elements with zero rendered size (display:none, collapsed, or not yet laid out); image-decode failures that returned a stub; upstream code that synthesized an ImageData without setting width/height; passing a placeholder/empty buffer through the scaling path.","solutions":["Check image.width > 0 && image.height > 0 before calling scaleImageToSize.","Fix the upstream producer: ensure the screenshot/decode actually returned pixels (await element to be visible and have non-zero bounding box first).","Skip scaling for degenerate images and pass them through unchanged or drop them."],"exampleFix":"// before\nconst scaled = scaleImageToSize(img, { width: 64, height: 64 }); // img.width === 0\n\n// after\nif (img.width <= 0 || img.height <= 0) throw new Error('cannot scale empty image');\nconst scaled = scaleImageToSize(img, { width: 64, height: 64 });","handlingStrategy":"type-guard","validationCode":"function isScalableImage(img: {width:number;height:number;data:Buffer}): boolean {\n  return img.width > 0 && img.height > 0;\n}","typeGuard":"function isScalableImage(img: unknown): img is { width: number; height: number; data: Buffer } {\n  return !!img && typeof img === 'object'\n    && typeof (img as any).width === 'number' && (img as any).width > 0\n    && typeof (img as any).height === 'number' && (img as any).height > 0;\n}","tryCatchPattern":"try { return scaleImageToSize(img, target); }\ncatch (e) { if (e.message === 'Invalid input image') return img; /* passthrough */ throw e; }","preventionTips":["Ensure screenshot sources have non-zero rendered size (await visible + bounding box).","Validate decoded image dimensions before scaling.","Handle decode failures upstream rather than passing stubs into the scaler."],"tags":["image","screenshot","scaling","validation","dimensions"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}