{"record":{"id":"c1227cddff3ad92b","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-read-next-field-in-dogsketch-message-w","errorCode":null,"errorMessage":"cannot read next field in Dogsketch message: %w","messagePattern":"cannot read next field in Dogsketch message: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/protoparser/datadogsketches/parser.go","lineNumber":264,"sourceCode":"\tK   []int32\n\tN   []uint32\n}\n\n// unmarshalProtobuf decodes src to Dogsketch struct\nfunc (d *Dogsketch) unmarshalProtobuf(src []byte) (err error) {\n\td.Ts = 0\n\td.Cnt = 0\n\td.Min = 0.0\n\td.Max = 0.0\n\td.Sum = 0.0\n\td.K = nil\n\td.N = nil\n\n\tvar fc easyproto.FieldContext\n\tfor len(src) > 0 {\n\t\tsrc, err = fc.NextField(src)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot read next field in Dogsketch message: %w\", err)\n\t\t}\n\t\tswitch fc.FieldNum {\n\t\tcase 1:\n\t\t\tts, ok := fc.Int64()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot read timestamp\")\n\t\t\t}\n\t\t\td.Ts = ts\n\t\tcase 2:\n\t\t\tcnt, ok := fc.Int64()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot read count\")\n\t\t\t}\n\t\t\td.Cnt = cnt\n\t\tcase 3:\n\t\t\tv, ok := fc.Double()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot read min\")","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/protoparser/datadogsketches/parser.go#L246-L282","documentation":"Returned by Dogsketch.unmarshalProtobuf when easyproto's NextField cannot parse the next field header inside a Dogsketch submessage — the bytes are not a valid protobuf field stream (truncated tag, invalid varint, or length overrun). It is wrapped up the chain as 'cannot unmarshal Sketch: cannot unmarshal Dogsketch: %w'.","triggerScenarios":"The Dogsketch submessage length prefix overstates the available bytes or its content contains an invalid field key — typically truncation or non-protobuf garbage in field-7 data of a Sketch.","commonSituations":"Payload truncation at a proxy/buffer boundary; producers writing partial sketches after a crash; fuzz testing ingestion endpoints that accept /api/beta/sketches payloads.","solutions":["Check for truncation: compare received byte count with the declared Content-Length / message size.","Decode the failing submessage with protoc --decode_raw to locate the malformed header.","Upgrade/align producer and parser on the same agent-payload Dogsketch schema.","Handle as a bad request at the ingestion layer and drop the payload."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify declared submessage length fits in the buffer before parsing\nfunc fits(b []byte, declared int) bool { return declared >= 0 && declared <= len(b) }","typeGuard":null,"tryCatchPattern":"if err := sp.UnmarshalProtobuf(buf); err != nil {\n    if strings.Contains(err.Error(), \"cannot read next field in Dogsketch\") {\n        log.Printf(\"truncated/corrupt dogsketch, dropping payload: %v\", err)\n        http.Error(w, \"malformed sketch payload\", http.StatusBadRequest)\n        return\n    }\n    return err\n}","preventionTips":["Check Content-Length vs bytes read to prevent truncation","Buffer the full request body before parsing","Reject unknown wire types at the edge","Fuzz-test the parser against truncated inputs"],"tags":["protobuf","parsing","malformed-input","datadog"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}