elsa-workflows/elsa-core · error · InvalidDataException

Invalid protobuf varint.

Error message

Invalid protobuf varint.

What it means

After 10 varint bytes without a terminating byte (high bit 0), the value would exceed the 64-bit protobuf varint maximum, which is invalid per the protobuf spec. The parser throws InvalidDataException "Invalid protobuf varint." to signal a malformed or maliciously crafted payload.

Solutions

  1. Confirm the sender produces standard protobuf encodings (varints max 10 bytes) — validate with a reference decoder.
  2. Check for byte corruption in transit (TLS termination, proxies) and test the exporter directly against the endpoint.
  3. If the body is intentionally not protobuf, send it to the correct endpoint or format.
Defensive patterns

Strategy: validation

Validate before calling

// Validate before export with a reference protobuf decoder:
// otel-cli export --protocol http/protobuf --endpoint ... or Protobuf.CodedInputStream round-trip

Try / catch

try { ParseProtobuf(body); }
catch (InvalidDataException ex) when (ex.Message == "Invalid protobuf varint.")
{ logger.LogWarning(ex, "Body is not valid protobuf; check sender format."); }

Prevention

When it happens

Trigger: Decoding an OTLP buffer where a varint field has 10+ continuation bytes (each with the high bit set) — e.g. corrupted bytes, random data posted to the endpoint, or a buggy custom encoder emitting oversized varints.

Common situations: Sending binary garbage or base64 text to the OTLP protobuf endpoint; intermediary mangling bytes; a hand-rolled encoder bug producing 11-byte 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 elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/bed691bfe7bf5714. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Diagnostics.OpenTelemetry/Ingestion/HttpProtobuf/OtlpHttpProtobufParser.cs:692

            ulong value = 0;
            var shift = 0;

            for (var i = 0; i < 10; i++)
            {
                if (_remaining.IsEmpty)
                    throw new InvalidDataException("Unexpected end of protobuf payload.");

                var b = _remaining[0];
                _remaining = _remaining[1..];
                value |= (ulong)(b & 0x7f) << shift;

                if ((b & 0x80) == 0)
                    return value;

                shift += 7;
            }

            throw new InvalidDataException("Invalid protobuf varint.");
        }

        private readonly void EnsureAvailable(int byteCount)
        {
            if (_remaining.Length < byteCount)
                throw new InvalidDataException("Unexpected end of protobuf payload.");
        }
    }
}

View on GitHub (pinned to fe9217bdfa)