{"record":{"id":"5a3db77e15020eba","repo":"openzipkin/zipkin","slug":"malformed-invalid-wiretype","errorCode":null,"errorMessage":"Malformed: invalid wireType ","messagePattern":"Malformed: invalid wireType ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"zipkin/src/main/java/zipkin2/internal/Proto3Fields.java","lineNumber":58,"sourceCode":"      this(key >>> 3, key & (1 << 3) - 1, key);\n    }\n\n    Field(int fieldNumber, int wireType, int key) {\n      this.fieldNumber = fieldNumber;\n      this.wireType = wireType;\n      this.key = key;\n    }\n\n    static int fieldNumber(int key, int byteL) {\n      int fieldNumber = key >>> 3;\n      if (fieldNumber != 0) return fieldNumber;\n      throw new IllegalArgumentException(\"Malformed: fieldNumber was zero at byte \" + byteL);\n    }\n\n    static int wireType(int key, int byteL) {\n      int wireType = key & (1 << 3) - 1;\n      if (wireType != 0 && wireType != 1 && wireType != 2 && wireType != 5) {\n        throw new IllegalArgumentException(\n          \"Malformed: invalid wireType \" + wireType + \" at byte \" + byteL);\n      }\n      return wireType;\n    }\n\n    static boolean skipValue(ReadBuffer buffer, int wireType) {\n      int remaining = buffer.available();\n      switch (wireType) {\n        case WIRETYPE_VARINT:\n          for (int i = 0; i < remaining; i++) {\n            if (buffer.readByte() >= 0) return true;\n          }\n          return false;\n        case WIRETYPE_FIXED64:\n          return buffer.skip(8) == 8;\n        case WIRETYPE_LENGTH_DELIMITED:\n          int length = buffer.readVarint32();\n          return buffer.skip(length) == length;","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin/src/main/java/zipkin2/internal/Proto3Fields.java#L40-L76","documentation":"A protobuf tag's low 3 bits encode the wire type; only values 0 (varint), 1 (64-bit), 2 (length-delimited), 5 (32-bit) are legal in Zipkin's reader (groups 3/7 are unused/obsolete). Proto3Fields.Field.wireType throws 'Malformed: invalid wireType N at byte P' when the key decodes to wire type 3, 4, 6, or 7, meaning the stream is corrupt or not protobuf.","triggerScenarios":"PROTO3 span decoding hits a tag whose key & 0x7 yields an illegal value — usually the reader is misaligned (after a bad length or truncated varint) or the bytes are another format entirely.","commonSituations":"Non-proto bytes fed to the proto3 decoder; a producer writing wrong varint tags; corrupted blobs in storage; concatenating two encodings without proper framing.","solutions":["Use the reported byte offset to hex-dump the region and confirm whether the stream is proto3 at all.","Check the preceding field's length prefix for off-by-one bugs in any custom encoding path.","Send the payload through a reference protobuf parser (protoc --decode with zipkin2.proto) to locate the first invalid tag.","Fix the producer to use SpanBytesEncoder.PROTO3 instead of hand-rolled serialization."],"exampleFix":"// before\n// custom hand-rolled encoder wrote field key 0x1d (wireType 5) for a string\n\n// after\n// use the shipped codec so tags are always well-formed\nbyte[] bytes = SpanBytesEncoder.PROTO3.encode(span);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { decode(bytes); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"invalid wireType\")) { quarantine(bytes); return List.of(); } throw e; }","preventionTips":["Validate payloads with protoc --decode in a pre-prod stage.","Avoid concatenating encodings; use one message per queue item.","Add checksums (CRC32) over span blobs on internal transports."],"tags":["zipkin","protobuf","malformed","wire-type"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}