{"record":{"id":"9beef97edb8e3831","repo":"iflytek/astron-agent","slug":"99999-system-error","errorCode":"99999","errorMessage":"system.error","messagePattern":"system\\.error","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java","lineNumber":38,"sourceCode":"public class ImageUtil {\n\n    /**\n     * Convert base64 string to InputStream\n     *\n     * @param base64String Base64 encoded image string\n     * @return InputStream object\n     */\n    public static InputStream base64ToImageInputStream(String base64String) {\n        if (base64String == null || base64String.trim().isEmpty()) {\n            throw new IllegalArgumentException(\"Base64 string cannot be empty\");\n        }\n\n        try {\n            byte[] byteArray = Base64.getDecoder().decode(base64String);\n            return new ByteArrayInputStream(byteArray);\n        } 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","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/ImageUtil.java#L20-L56","documentation":"When the Base64 decode itself fails (e.g. the string contains illegal characters or wrong padding), the method catches the exception, logs it, and rethrows the generic BusinessException SYSTEM_ERROR (code 99999). The generic code hides the real decode failure, so check the server log for 'Failed to convert Base64 string to InputStream'.","triggerScenarios":"Passing a string that is not valid Base64: contains characters outside the Base64 alphabet, wrong length not a multiple of 4, missing/incorrect padding, or a full data URL like \"data:image/png;base64,AAAA\" passed without stripping the prefix.","commonSituations":"Frontend sends a data-URI instead of raw Base64, URL-safe Base64 (-/_) used where standard Base64 (+//) is expected, copy-paste truncating the string, or JSON transport mangling '+' characters in form-encoded requests.","solutions":["Inspect the server log at ImageUtil.java for the wrapped stack trace to see the actual decoder error","Strip the \"data:image/...;base64,\" prefix before passing the string","Validate the string matches ^[A-Za-z0-9+/]*={0,2}$ and has length % 4 == 0 before calling","If the source uses URL-safe Base64, convert '-'->'+' and '_'->'/' and re-pad before decoding"],"exampleFix":"// before\nInputStream in = ImageUtil.base64ToImageInputStream(dataUrl); // \"data:image/png;base64,iVBOR...\"\n// after\nString b64 = dataUrl.substring(dataUrl.indexOf(\",\") + 1); // strip data-URL prefix\nInputStream in = ImageUtil.base64ToImageInputStream(b64);","handlingStrategy":"validation","validationCode":"boolean isRawBase64(String s) { return s != null && s.matches(\"^[A-Za-z0-9+/\\\\r\\\\n]+={0,2}$\") && s.replaceAll(\"\\\\s\", \"\").length() % 4 == 0; }","typeGuard":null,"tryCatchPattern":"try { InputStream in = ImageUtil.base64ToImageInputStream(b64); } catch (BusinessException e) { log.error(\"base64 image decode failed for request {}\", reqId, e); throw new BadRequestException(\"invalid image data\"); }","preventionTips":["Strip the data-URL prefix before decoding","Never pass URL-safe Base64 to standard decoder-based utilities","Validate Base64 alphabet/padding before sending"],"tags":["java","base64","encoding","image"],"backgroundTag":"invalid-argument-format","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"}