{"record":{"id":"800f91cd3f572dfe","repo":"jenkinsci/jenkins","slug":"corrupt-stream-negative-operation-code","errorCode":null,"errorMessage":"corrupt stream: negative operation code","messagePattern":"corrupt stream: negative operation code","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"cli/src/main/java/hudson/cli/PlainCLIProtocol.java","lineNumber":189,"sourceCode":"        ProtocolException(String message) {\n            super(message);\n        }\n    }\n\n    abstract static class EitherSide implements Closeable {\n\n        private final Output out;\n\n        protected EitherSide(Output out) {\n            this.out = out;\n        }\n\n        protected abstract void handleClose();\n\n        final void handle(DataInputStream dis) throws IOException {\n            byte b = dis.readByte();\n            if (b < 0) { // i.e., >127\n                throw new IOException(\"corrupt stream: negative operation code\");\n            }\n            if (b >= Op.values().length) {\n                throw new ProtocolException(\"unknown operation #\" + b);\n            }\n            Op op = Op.values()[b];\n            LOGGER.finest(() -> \"handling frame with \" + op);\n            if (!handle(op, dis)) {\n                throw new ProtocolException(\"unhandled: \" + op);\n            }\n        }\n\n        protected abstract boolean handle(Op op, DataInputStream dis) throws IOException;\n\n        protected final synchronized void send(Op op) throws IOException {\n            send(op, new byte[0], 0, 0);\n        }\n\n        protected final synchronized void send(Op op, int v) throws IOException {","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/cli/src/main/java/hudson/cli/PlainCLIProtocol.java#L171-L207","documentation":"Thrown by PlainCLIProtocol.EitherSide.handle when the opcode byte read from a frame is negative (i.e. its unsigned value is > 127). The Op enum is indexed 0..n-1, so a high byte indicates the stream is corrupted or the peer is sending data that is not part of this protocol.","triggerScenarios":"Payload bytes are being interpreted as an opcode because a previous frame was misaligned (wrong length), or the stream is not a PlainCLIProtocol stream at all.","commonSituations":"Frame-length corruption feeding garbage to the opcode reader; mid-stream injection by a proxy; protocol version skew between client and server.","solutions":["Reconnect with a CLI jar matching the controller version to rule out protocol skew.","Check authentication and URL so no HTML/error content enters the stream.","Eliminate any intermediary that modifies the streamed bytes."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    side.handle(dis);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"negative operation code\")) {\n        // treat the connection as corrupt: tear down and reconnect with aligned versions\n        connection.close();\n    } else throw e;\n}","preventionTips":["Align client and server protocol versions.","Prevent any intermediary from injecting bytes into the stream.","Validate authentication so no HTML content reaches the frame reader."],"tags":["jenkins-cli","protocol","stream-corruption","opcode"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}