thanos-io/thanos · error

proto: integer overflow

Error message

proto: integer overflow

What it means

ErrIntOverflowRpc is a sentinel generated in gogo-protobuf's rpc.pb.go. During varint decoding, if the shift counter reaches 64 bits the encoded value exceeds uint64 capacity, so decoding aborts with this error. It protects against malicious or corrupt inputs claiming enormous lengths.

Solutions

  1. Sanitize/validate the payload source; do not unmarshal untrusted bytes without length limits.
  2. Verify both ends use the same proto schema and serializer version.
  3. Check for buffer-offset bugs that shift the parse position mid-message.
  4. Reject the input permanently — retrying the same bytes will fail identically.

Example fix

// before
if err := proto.Unmarshal(data, msg); err != nil { return err }
// after
if err := proto.Unmarshal(data, msg); err != nil {
    if errors.Is(err, errpb.ErrIntOverflowRpc) { return errors.Wrap(err, "malformed varint in payload") }
    return err
}
Defensive patterns

Strategy: try-catch

Validate before calling

if len(data) > maxAllowedProtoSize { return errors.New("payload exceeds size limit") }

Try / catch

if err := proto.Unmarshal(data, msg); err != nil {
    if errors.Is(err, ErrIntOverflowRpc) { return errors.Wrap(err, "corrupt protobuf: varint overflow") }
    return err
}

Prevention

When it happens

Trigger: Unmarshaling a protobuf message containing a varint with 10+ continuation bytes (shift >= 64), typically in the length prefix of a string/bytes/embedded-message field.

Common situations: Corrupt or hostile payloads, truncated-then-repadded byte streams, or feeds from an incompatible proto writer emitting malformed varints.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/588855271fcd07ea. Report an issue: GitHub.

Appendix: source

Thrown at pkg/status/statuspb/rpc.pb.go:2005

			depth--
		case 5:
			iNdEx += 4
		default:
			return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
		}
		if iNdEx < 0 {
			return 0, ErrInvalidLengthRpc
		}
		if depth == 0 {
			return iNdEx, nil
		}
	}
	return 0, io.ErrUnexpectedEOF
}

var (
	ErrInvalidLengthRpc        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowRpc          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupRpc = fmt.Errorf("proto: unexpected end of group")
)

View on GitHub (pinned to 35b8b99117)