{"record":{"id":"aa018dd1674529e1","repo":"bumptech/glide","slug":"cannot-scale-with-factor-exactscalefactor-from","errorCode":null,"errorMessage":"Cannot scale with factor: {exactScaleFactor} from: {downsampleStrategy}, source: [{sourceWidth}x{sourceHeight}], target: [{targetWidth}x{targetHeight}]","messagePattern":"Cannot scale with factor: (.+?) from: (.+?), source: \\[(.+?)x(.+?)\\], target: \\[(.+?)x(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java","lineNumber":549,"sourceCode":"    }\n\n    int orientedSourceWidth = sourceWidth;\n    int orientedSourceHeight = sourceHeight;\n    // If we're rotating the image +-90 degrees, we need to downsample accordingly so the image\n    // width is decreased to near our target's height and the image height is decreased to near\n    // our target width.\n    //noinspection SuspiciousNameCombination\n    if (isRotationRequired(degreesToRotate)) {\n      orientedSourceWidth = sourceHeight;\n      orientedSourceHeight = sourceWidth;\n    }\n\n    final float exactScaleFactor =\n        downsampleStrategy.getScaleFactor(\n            orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight);\n\n    if (exactScaleFactor <= 0f) {\n      throw new IllegalArgumentException(\n          \"Cannot scale with factor: \"\n              + exactScaleFactor\n              + \" from: \"\n              + downsampleStrategy\n              + \", source: [\"\n              + sourceWidth\n              + \"x\"\n              + sourceHeight\n              + \"]\"\n              + \", target: [\"\n              + targetWidth\n              + \"x\"\n              + targetHeight\n              + \"]\");\n    }\n\n    SampleSizeRounding rounding =\n        downsampleStrategy.getSampleSizeRounding(","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java#L531-L567","documentation":"Thrown by Downsampler when DownsampleStrategy.getScaleFactor() returns a value <= 0 for the given source and target dimensions. Glide interprets a non-positive scale factor as the strategy being unable to produce a valid downsampling ratio, so decoding is aborted rather than producing a corrupt or zero-size bitmap.","triggerScenarios":"A custom DownsampleStrategy whose getScaleFactor returns 0 or a negative number (often when sourceWidth or sourceHeight is 0). Decoding an image with reported 0x0 dimensions, or a corrupted/truncated image header where the decoder reports zero source dimensions.","commonSituations":"Registering a custom DownsampleStrategy via .set(DownsampleStrategy.OPTION, customStrategy) that has an edge case returning 0. Loading a malformed GIF/PNG/WebP whose metadata reports 0 dimensions. DownsampleStrategy.NONE misused together with a target of 0.","solutions":["Inspect the source image: if the source reports 0x0 dimensions the file is corrupt; replace or skip it.","If using a custom DownsampleStrategy, ensure getScaleFactor always returns > 0 for positive inputs (e.g. fall back to 1f).","Validate image dimensions before requesting decode, or use .error()/fallback to handle corrupt sources gracefully.","Switch to a built-in DownsampleStrategy (DEFAULT, CENTER_OUTSIDE) to rule out custom-strategy bugs."],"exampleFix":"// before\npublic float getScaleFactor(int sw, int sh, int tw, int th) {\n  return tw == 0 ? 0f : (float) tw / sw; // returns 0 when target width is 0\n}\n// after\npublic float getScaleFactor(int sw, int sh, int tw, int th) {\n  if (sw <= 0 || sh <= 0) return 1f;\n  return tw <= 0 ? 1f : Math.max((float) tw / sw, (float) th / sh);\n}","handlingStrategy":"validation","validationCode":"// Before decoding, verify source dimensions are positive.\nBitmapFactory.Options opts = new BitmapFactory.Options();\nopts.inJustDecodeBounds = true;\nBitmapFactory.decodeStream(input.markSupported() ? input : new BufferedInputStream(input), null, opts);\nif (opts.outWidth <= 0 || opts.outHeight <= 0) {\n  // skip / fallback instead of letting Downsampler throw\n}","typeGuard":null,"tryCatchPattern":"try { Glide.with(ctx).load(url).into(target); }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot scale with factor\")) {\n    // log corrupt image, show placeholder\n  } else throw e;\n}","preventionTips":["Validate image headers before decoding when sources are user-supplied.","If using a custom DownsampleStrategy, unit-test getScaleFactor for 0 inputs.","Provide an .error() drawable for corrupt sources."],"tags":["downsample","decode","dimensions","bitmap","android"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}