{"record":{"id":"e6aa3c03f075143d","repo":"iflytek/astron-agent","slug":"compression-ratio-must-be-between-0-1","errorCode":null,"errorMessage":"Compression ratio must be between 0-1","messagePattern":"Compression ratio must be between 0-1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java","lineNumber":54,"sourceCode":"        } catch (Exception e) {\n            log.error(\"Failed to convert Base64 string to InputStream\", e);\n            throw new BusinessException(SYSTEM_ERROR);\n        }\n    }\n\n    /**\n     * Compress image\n     *\n     * @param inputStream Original image input stream\n     * @param scale Compression ratio (0.0-1.0)\n     * @return Compressed image input stream\n     */\n    public static InputStream compressImage(InputStream inputStream, float scale) {\n        if (inputStream == null) {\n            throw new IllegalArgumentException(\"Input stream cannot be empty\");\n        }\n        if (scale <= 0 || scale > 1) {\n            throw new IllegalArgumentException(\"Compression ratio must be between 0-1\");\n        }\n\n        ByteArrayOutputStream outputStream = null;\n        try {\n            outputStream = new ByteArrayOutputStream();\n            ImgUtil.scale(inputStream, outputStream, scale);\n            return new ByteArrayInputStream(outputStream.toByteArray());\n        } catch (Exception e) {\n            log.error(\"Image compression failed, scale: {}\", scale, e);\n            throw new BusinessException(SYSTEM_ERROR);\n        } finally {\n            IoUtil.close(inputStream);\n            IoUtil.close(outputStream);\n        }\n    }\n}\n","sourceCodeStart":36,"sourceCodeEnd":71,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java#L36-L71","documentation":"compressImage validates that the compression ratio (scale) lies strictly between 0 and 1 and throws IllegalArgumentException otherwise. This is a caller-side argument contract, not an image-processing failure.","triggerScenarios":"Calling ImageUtil.compressImage(stream, 0), a negative value like -0.2, or 1.0 / greater values (e.g. 1.5 intending 'enlarge').","commonSituations":"Confusing scale-as-percentage (50 for 50%) with scale-as-fraction (0.5), passing quality (0-100) instead of scale, or a config default of 0 meaning 'no compression'.","solutions":["Convert the caller's value to a fraction: divide a percentage by 100 (e.g. 50 -> 0.5f)","Use a value in (0, 1]; e.g. 0.5f for half-size. Use 1.0 carefully — the check rejects values > 1, and scale must be > 0","Clamp or validate user-supplied scale from config/API before invoking"],"exampleFix":"// before\nfloat scale = 50; // percent\nInputStream out = ImageUtil.compressImage(in, scale); // throws\n// after\nfloat scale = 50 / 100f; // 0.5f\nInputStream out = ImageUtil.compressImage(in, scale);","handlingStrategy":"validation","validationCode":"if (scale <= 0f || scale > 1f) { throw new BadRequestException(\"scale must be in (0, 1]\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize percent inputs (divide by 100) before calling","Clamp config-driven scale values into (0, 1] at load time"],"tags":["java","validation","image","argument"],"backgroundTag":"argument-out-of-range","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}