{"record":{"id":"5e6bf215f5150328","repo":"apache/beam","slug":"invalid-varintz-encoding-for-v","errorCode":null,"errorMessage":"invalid varintz encoding for: %v","messagePattern":"invalid varintz encoding for: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/coderx/varint.go","lineNumber":74,"sourceCode":"\t\tval = int64(n)\n\tcase int16:\n\t\tval = int64(n)\n\tcase int32:\n\t\tval = int64(n)\n\tcase int64:\n\t\tval = n\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"received unknown value type: want a signed integer:, got %T\", n))\n\t}\n\tret := make([]byte, binary.MaxVarintLen64)\n\tsize := binary.PutVarint(ret, val)\n\treturn ret[:size]\n}\n\nfunc decVarIntZ(t reflect.Type, data []byte) (typex.T, error) {\n\tn, size := binary.Varint(data)\n\tif size <= 0 {\n\t\treturn nil, errors.Errorf(\"invalid varintz encoding for: %v\", data)\n\t}\n\tswitch t.Kind() {\n\tcase reflect.Int:\n\t\treturn int(n), nil\n\tcase reflect.Int8:\n\t\treturn int8(n), nil\n\tcase reflect.Int16:\n\t\treturn int16(n), nil\n\tcase reflect.Int32:\n\t\treturn int32(n), nil\n\tcase reflect.Int64:\n\t\treturn n, nil\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unreachable statement: expected a signed integer, got %v\", t))\n\t}\n}\n\nfunc encVarUintZ(v typex.T) []byte {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/coderx/varint.go#L56-L92","documentation":"decVarIntZ decodes bytes with binary.Varint (zig-zag). If Varint returns size <= 0 the data is empty, truncated, or malformed, and this error is returned. It indicates the byte stream doesn't conform to the varintz scheme, not that the decoded value is out of range.","triggerScenarios":"Decoding (via the 'varintz' custom coder) byte slices not produced by encVarIntZ — wrong coder, truncated buffer, corrupted storage.","commonSituations":"Mixing varintz and varuintz encoded data, reading partial records from a stream, cross-version data with a changed encoding.","solutions":["Ensure decoding uses the same coder (NewVarIntZ) used to encode the data.","Check buffer boundaries — a truncated record yields size <= 0; fix the framing/length prefix.","Compare encodings: varintz (binary.Varint) differs from Beam's standard varint; don't mix schemes.","Hex-dump the offending bytes to verify the first byte is a valid varint continuation sequence."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// validate a buffer before varintz decode\nfunc validVarIntZ(data []byte) bool {\n    _, size := binary.Varint(data)\n    return size > 0\n}","typeGuard":"func isVarIntZCoder(c *coder.CustomCoder) bool { return c.Name == \"varintz\" }","tryCatchPattern":"val, err := coder.Decode(data)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid varintz encoding\") {\n        log.Warnf(\"bad varintz record: % x\", data)\n        return nil, nil // dead-letter instead\n    }\n    return nil, err\n}","preventionTips":["Encode and decode with the same NewVarIntZ coder; never mix with varuintz.","Frame records with explicit lengths so decoders never see truncated buffers.","Note varintz uses Go's zig-zag binary.Varint, not Beam's standard varint — don't cross decode.","Checksum stored records to catch corruption before decode."],"tags":["go","apache-beam","decoding","varint","corrupt-data"],"backgroundTag":"invalid-argument-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}