{"record":{"id":"4d30dd1acdd481ae","repo":"openjdk/jdk","slug":"s-n","errorCode":null,"errorMessage":"%s\\n","messagePattern":"%s\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/java.desktop/share/native/libjavajpeg/jpegdecoder.c","lineNumber":142,"sourceCode":"}\n\n/*\n * Error Message handling\n *\n * This overrides the output_message method to send JPEG messages\n *\n */\n\nMETHODDEF(void)\nsun_jpeg_output_message (j_common_ptr cinfo)\n{\n  char buffer[JMSG_LENGTH_MAX];\n\n  /* Create the message */\n  (*cinfo->err->format_message) (cinfo, buffer);\n\n  /* Send it to stderr, adding a newline */\n  fprintf(stderr, \"%s\\n\", buffer);\n}\n\n\n\n\n/*\n * INPUT HANDLING:\n *\n * The JPEG library's input management is defined by the jpeg_source_mgr\n * structure which contains two fields to convey the information in the\n * buffer and 5 methods which perform all buffer management.  The library\n * defines a standard input manager that uses stdio for obtaining compressed\n * jpeg data, but here we need to use Java to get our data.\n *\n * We need to make the Java class information accessible to the source_mgr\n * input routines.  We also need to store a pointer to the start of the\n * Java array being used as an input buffer so that it is not moved or\n * garbage collected while the JPEG library is using it.  To store these","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c#L124-L160","documentation":"This is not one error but the JDK's jpegdecoder.c replacement for libjpeg's default output_message callback: every warning or recoverable error that libjpeg emits while decoding (via format_message) is printed to stderr with a newline. Seeing this format string in a log means libjpeg produced a diagnostic — the actual text (e.g. 'Corrupt JPEG data: premature end of data segment', 'Unsupported marker type') is in the buffer, not in the format itself.","triggerScenarios":"Toolkit.createImage()/ImageIO-style loading (via sun.awt.image JPEG decoder) of a JPEG that is truncated, has corrupt Huffman data, unknown JPEG markers, or uses progressive/color profiles libjpeg only partially supports. Each such condition makes libjpeg call output_message, which prints and, for warnings, continues decoding.","commonSituations":"Downloading images over flaky connections producing truncated files; camera-generated JPEGs with EXIF/markers the decoder warns about; CMYK or 12-bit JPEGs; images renamed to .jpg that are actually something else. The message is informational: decoding usually still succeeds with minor artifacts.","solutions":["Read the message text after the format — it names the exact libjpeg problem; address that (re-save the image, fix transfer, strip EXIF)","Verify the file is a complete JPEG: check SOI/EOI markers (FFD8...FFD9) and file size before decoding","Re-encode the problem image with a standard tool (cjpeg/ImageMagick) to normalize markers and color space","If the image is under your control, export baseline RGB JPEG rather than progressive/CMYK"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before decoding, verify JPEG SOI/EOI and size\nbyte[] b = Files.readAllBytes(Path.of(\"img.jpg\"));\nboolean looksLikeJpeg = b.length > 4\n    && (b[0] & 0xFF) == 0xFF && (b[1] & 0xFF) == 0xD8\n    && (b[b.length-2] & 0xFF) == 0xFF && (b[b.length-1] & 0xFF) == 0xD9;\nif (!looksLikeJpeg) throw new IOException(\"not a complete JPEG\");","typeGuard":null,"tryCatchPattern":"catch (IOException | ArrayIndexOutOfBoundsException e) when loading; the stderr line itself is non-fatal libjpeg diagnostics — decide on partial-image acceptability","preventionTips":["Check content, not file extension, before decode","Validate transferred images with checksums so truncation is caught upstream","Normalize user-supplied images through a re-encode step in your pipeline"],"tags":["jpeg","image-decoding","libjpeg","awt","native"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}