{"record":{"id":"a2768adcd2dd02ae","repo":"jenkinsci/jenkins","slug":"corrupt-stream","errorCode":null,"errorMessage":"Corrupt stream","messagePattern":"Corrupt stream","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/hudson/console/ConsoleNote.java","lineNumber":255,"sourceCode":"     */\n    public static ConsoleNote readFrom(DataInputStream in) throws IOException, ClassNotFoundException {\n        try {\n            byte[] preamble = new byte[PREAMBLE.length];\n            in.readFully(preamble);\n            if (!Arrays.equals(preamble, PREAMBLE))\n                return null;    // not a valid preamble\n\n            byte[] mac;\n            byte[] buf;\n            try (DataInputStream decoded = new DataInputStream(Base64.getDecoder().wrap(in))) {\n                int macSz = -decoded.readInt();\n                int sz;\n                if (macSz > 0) { // new format\n                    mac = new byte[macSz];\n                    decoded.readFully(mac);\n                    sz = decoded.readInt();\n                    if (sz < 0) {\n                        throw new IOException(\"Corrupt stream\");\n                    }\n                } else {\n                    mac = null;\n                    sz = -macSz;\n                }\n                buf = new byte[sz];\n                decoded.readFully(buf);\n            }\n\n            byte[] postamble = new byte[POSTAMBLE.length];\n            in.readFully(postamble);\n            if (!Arrays.equals(postamble, POSTAMBLE))\n                return null;    // not a valid postamble\n\n            if (!INSECURE) {\n                if (mac == null) {\n                    throw new IOException(\"Refusing to deserialize unsigned note from an old log.\");\n                } else if (!MAC.checkMac(buf, mac)) {","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/console/ConsoleNote.java#L237-L273","documentation":"IOException from ConsoleNote.readFrom when an encoded note in the new (MAC) format declares a negative payload size (sz < 0). A negative sz means the encoded bytes are corrupt/truncated/malformed. readFrom also wraps any Error (e.g. OutOfMemoryError from a bogus size) as IOException so one bad note does not kill the reader.","triggerScenarios":"Reading back a console log whose encoded note bytes are truncated or corrupted at the size field.","commonSituations":"Disk-full or crashed write left a partial note; log file truncated/rotated mid-note; file copied/migrated with byte corruption.","solutions":["Restore the log from a clean backup, or accept truncation past the corrupt note.","If you control the reader, catch IOException per-note and continue (the note is skipped, surrounding text remains).","Investigate the writer/disk if corruption recurs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    ConsoleNote note = ConsoleNote.readFrom(in);\n} catch (IOException e) {\n    // corrupt note: skip it, keep rendering surrounding text\n}","preventionTips":["Catch IOException per-note when streaming logs so one bad note does not abort the read.","Guard write paths against partial writes (disk full)."],"tags":["console","io","corruption"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}