jenkinsci/jenkins · error · IOException

Corrupt stream

Error message

Corrupt stream

What it means

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.

Source

Thrown at core/src/main/java/hudson/console/ConsoleNote.java:255

     */
    public static ConsoleNote readFrom(DataInputStream in) throws IOException, ClassNotFoundException {
        try {
            byte[] preamble = new byte[PREAMBLE.length];
            in.readFully(preamble);
            if (!Arrays.equals(preamble, PREAMBLE))
                return null;    // not a valid preamble

            byte[] mac;
            byte[] buf;
            try (DataInputStream decoded = new DataInputStream(Base64.getDecoder().wrap(in))) {
                int macSz = -decoded.readInt();
                int sz;
                if (macSz > 0) { // new format
                    mac = new byte[macSz];
                    decoded.readFully(mac);
                    sz = decoded.readInt();
                    if (sz < 0) {
                        throw new IOException("Corrupt stream");
                    }
                } else {
                    mac = null;
                    sz = -macSz;
                }
                buf = new byte[sz];
                decoded.readFully(buf);
            }

            byte[] postamble = new byte[POSTAMBLE.length];
            in.readFully(postamble);
            if (!Arrays.equals(postamble, POSTAMBLE))
                return null;    // not a valid postamble

            if (!INSECURE) {
                if (mac == null) {
                    throw new IOException("Refusing to deserialize unsigned note from an old log.");
                } else if (!MAC.checkMac(buf, mac)) {

View on GitHub (pinned to 2e228ff40b)

Solutions

  1. Restore the log from a clean backup, or accept truncation past the corrupt note.
  2. If you control the reader, catch IOException per-note and continue (the note is skipped, surrounding text remains).
  3. Investigate the writer/disk if corruption recurs.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    ConsoleNote note = ConsoleNote.readFrom(in);
} catch (IOException e) {
    // corrupt note: skip it, keep rendering surrounding text
}

Prevention

When it happens

Trigger: Reading back a console log whose encoded note bytes are truncated or corrupted at the size field.

Common situations: Disk-full or crashed write left a partial note; log file truncated/rotated mid-note; file copied/migrated with byte corruption.

Related errors


AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14). Data as JSON: /api/errors/a2768adcd2dd02ae. Report an issue: GitHub.