{"record":{"id":"64cfe0022e0f196e","repo":"thanos-io/thanos","slug":"proto-negative-length-found-during-unmarshaling","errorCode":null,"errorMessage":"proto: negative length found during unmarshaling","messagePattern":"proto: negative length found during unmarshaling","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/status/statuspb/rpc.pb.go","lineNumber":2004,"sourceCode":"\t\t\t}\n\t\t\tdepth--\n\t\tcase 5:\n\t\t\tiNdEx += 4\n\t\tdefault:\n\t\t\treturn 0, fmt.Errorf(\"proto: illegal wireType %d\", wireType)\n\t\t}\n\t\tif iNdEx < 0 {\n\t\t\treturn 0, ErrInvalidLengthRpc\n\t\t}\n\t\tif depth == 0 {\n\t\t\treturn iNdEx, nil\n\t\t}\n\t}\n\treturn 0, io.ErrUnexpectedEOF\n}\n\nvar (\n\tErrInvalidLengthRpc        = fmt.Errorf(\"proto: negative length found during unmarshaling\")\n\tErrIntOverflowRpc          = fmt.Errorf(\"proto: integer overflow\")\n\tErrUnexpectedEndOfGroupRpc = fmt.Errorf(\"proto: unexpected end of group\")\n)\n","sourceCodeStart":1986,"sourceCodeEnd":2008,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/status/statuspb/rpc.pb.go#L1986-L2008","documentation":"ErrInvalidLengthRpc is a sentinel generated into gogo-protobuf's rpc.pb.go files. It is returned when a decoded length (e.g. a string/bytes field length or a computed postIndex) is negative, which cannot happen with well-formed protobuf input. It signals that the marshaled data or offset arithmetic is corrupt.","triggerScenarios":"Unmarshaling a message where a length varint decodes to a negative value (int overflow of the length prefix) or iNdEx + length underflows, in any generated Unmarshal/skip function referencing ErrInvalidLengthRpc.","commonSituations":"Corrupt object-storage payloads, byte-offset bugs when reading message slices from a larger buffer, or schema mismatch producing misaligned varints.","solutions":["Check the buffer slicing logic that produced the byte slice passed to Unmarshal (correct offset and length).","Validate payload integrity (checksums, content-length) before unmarshaling.","Ensure all services use the same generated proto code version.","Return a 4xx/invalid-data error to the caller rather than retrying, since the input is malformed."],"exampleFix":"// before\nif err := proto.Unmarshal(chunk, msg); err != nil { return err }\n// after\nif len(chunk) == 0 { return errors.New(\"empty chunk\") }\nif err := proto.Unmarshal(chunk, msg); err != nil {\n    if errors.Is(err, errpb.ErrInvalidLengthRpc) { return errors.Wrap(err, \"malformed protobuf chunk\") }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if len(data) < 2 { return errors.New(\"payload too short to be valid protobuf\") }","typeGuard":null,"tryCatchPattern":"if err := proto.Unmarshal(data, msg); err != nil {\n    if errors.Is(err, ErrInvalidLengthRpc) { return errors.Wrap(err, \"corrupt protobuf: negative length\") }\n    return err\n}","preventionTips":["Checksum payloads in transit","Slice buffers with verified offsets","Pin gogo-protobuf codegen versions"],"tags":["protobuf","unmarshal","corrupt-data"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}