{"record":{"id":"d7f77b9119ecd947","repo":"gravitational/teleport","slug":"invalid-resize-dimensions","errorCode":null,"errorMessage":"invalid resize dimensions","messagePattern":"invalid resize dimensions","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/srv/desktop/rdp/decoder/decoder.go","lineNumber":172,"sourceCode":"\n\trgba := image.NewRGBA(image.Rect(0, 0, int(outWidth), int(outHeight)))\n\n\t// Copy from the Rust-owned memory into Go memory.\n\tcopy(rgba.Pix, unsafe.Slice((*uint8)(data), int(outWidth)*int(outHeight)*4))\n\n\treturn rgba\n}\n\n// ResizeCrop returns the source crop region (cropX, cropY, cropW, cropH) scaled to exactly outWidth x outHeight using\n// high-quality CatmullRom convolution. The crop must lie within the current frame bounds. When withCursor is true and\n// the decoder's tracked cursor is visible, it is composited onto the source frame before the crop is taken, so the\n// cursor scales with the screen.\nfunc (d *Decoder) ResizeCrop(cropX, cropY, cropW, cropH, outWidth, outHeight uint16, withCursor bool) (*image.RGBA, error) {\n\tif d == nil || d.ptr == nil {\n\t\treturn nil, errors.New(\"decoder not initialized\")\n\t}\n\tif outWidth == 0 || outHeight == 0 || cropW == 0 || cropH == 0 {\n\t\treturn nil, errors.New(\"invalid resize dimensions\")\n\t}\n\n\tbpp := int(C.rdp_decoder_bytes_per_pixel(d.ptr))\n\tif bpp == 0 {\n\t\treturn nil, errors.New(\"decoder has no pixel format\")\n\t}\n\n\tw, h := int(outWidth), int(outHeight)\n\tbuf := make([]byte, w*h*bpp)\n\n\tvar withCursorC C.uint8_t\n\tif withCursor {\n\t\twithCursorC = 1\n\t}\n\n\tok := C.rdp_decoder_resize_crop(\n\t\td.ptr,\n\t\tC.uint16_t(cropX),","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/gravitational/teleport/blob/1283425b60ec5f60d509ba4c791183d452923ff7/lib/srv/desktop/rdp/decoder/decoder.go#L154-L190","documentation":"ResizeCrop returns 'invalid resize dimensions' when any of outWidth, outHeight, cropW or cropH is zero. The crop must be a non-empty region scaled to a non-empty output; this is a cheap input sanity check before touching the native decoder.","triggerScenarios":"Calling ResizeCrop with a zero width/height for the output image or a zero-sized crop rectangle — usually from uninitialized screen-size variables or empty ClientScreenSpec values.","commonSituations":"Playback before the first client screen-spec arrives (0x0 requested size), malformed resize requests from the web UI, or a capture with a zero-area crop region.","solutions":["Wait for the client screen spec / first frame before requesting a resize","Validate width/height are non-zero at the API boundary and reject early","Fall back to the current frame dimensions when the requested size is 0","Log the incoming screen spec to find which client sends zero dimensions"],"exampleFix":"// before\nimg, err := dec.ResizeCrop(x, y, w, h, req.Width, req.Height, false)\n// after\nif req.Width == 0 || req.Height == 0 {\n  req.Width, req.Height = currentW, currentH\n}\nimg, err := dec.ResizeCrop(x, y, w, h, req.Width, req.Height, false)","handlingStrategy":"validation","validationCode":"if outWidth == 0 || outHeight == 0 || cropW == 0 || cropH == 0 {\n  return errors.New(\"resize requires non-zero output and crop dimensions\")\n}","typeGuard":null,"tryCatchPattern":"img, err := dec.ResizeCrop(x, y, cw, ch, ow, oh, false)\nif err != nil {\n  if strings.Contains(err.Error(), \"invalid resize dimensions\") {\n    ow, oh = frameW, frameH // fall back to native frame size\n    img, err = dec.ResizeCrop(x, y, cw, ch, ow, oh, false)\n  }\n  if err != nil { return nil, err }\n}","preventionTips":["Only render after the first ClientScreenSpec arrives","Validate client-requested sizes at the protocol boundary","Default zero sizes to the current frame dimensions instead of passing them through"],"tags":["rdp","decoder","validation","desktop-access"],"backgroundTag":"invalid-dimensions","analyzedSha":"1283425b60ec5f60d509ba4c791183d452923ff7","analyzedAt":"2026-09-02T04:06:41.601Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}