{"record":{"id":"53a9c5a6a0c2c0b0","repo":"canopy-network/canopy","slug":"invalid-field-value-at-offset-d","errorCode":null,"errorMessage":"invalid field value at offset %d","messagePattern":"invalid field value at offset (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/codec/codec.go","lineNumber":100,"sourceCode":"\t\t\t\t\treturn nil, fmt.Errorf(\"invalid length at offset %d\", offset)\n\t\t\t\t}\n\t\t\t\t// calculate the new offset\n\t\t\t\toffset += lenBytes\n\t\t\t\t// extract the field value bytes\n\t\t\t\tif offset+int(valueLen) > len(protoBytes) {\n\t\t\t\t\treturn nil, fmt.Errorf(\"field value exceeds buffer bounds\")\n\t\t\t\t}\n\t\t\t\t// make buffer to return\n\t\t\t\tfieldBytes := make([]byte, valueLen)\n\t\t\t\t// copy into the buffer\n\t\t\t\tcopy(fieldBytes, protoBytes[offset:offset+int(valueLen)])\n\t\t\t\t// return the value\n\t\t\t\treturn fieldBytes, nil\n\t\t\t} else {\n\t\t\t\t// for other wire types, consume the value directly\n\t\t\t\tvalueLen := protowire.ConsumeFieldValue(fieldNum, wireType, protoBytes[offset:])\n\t\t\t\tif valueLen < 0 {\n\t\t\t\t\treturn nil, fmt.Errorf(\"invalid field value at offset %d\", offset)\n\t\t\t\t}\n\t\t\t\tif offset+valueLen > len(protoBytes) {\n\t\t\t\t\treturn nil, fmt.Errorf(\"field value exceeds buffer bounds\")\n\t\t\t\t}\n\t\t\t\tfieldBytes := make([]byte, valueLen)\n\t\t\t\tcopy(fieldBytes, protoBytes[offset:offset+valueLen])\n\t\t\t\treturn fieldBytes, nil\n\t\t\t}\n\t\t} else {\n\t\t\t// skip this field\n\t\t\tskipLen := protowire.ConsumeFieldValue(fieldNum, wireType, protoBytes[offset:])\n\t\t\tif skipLen < 0 {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid field value at offset %d\", offset)\n\t\t\t}\n\t\t\toffset += skipLen\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"%w: %d\", ErrFieldNotFound, fieldNumber)","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/canopy-network/canopy/blob/ee8197d91dd410f6592cb650a94c925ee6dc8bad/lib/codec/codec.go#L82-L118","documentation":"For a matching field with a non-bytes wire type (varint, fixed32, fixed64, etc.), GetRawProtoField consumes the value with protowire.ConsumeFieldValue. A negative result means the value bytes are malformed or the buffer ends inside the value — the wire data at this offset cannot be parsed as the declared wire type.","triggerScenarios":"GetRawProtoField on corrupted/truncated wire bytes where the target field's value (e.g. a varint) is cut short or encodes an invalid pattern.","commonSituations":"Bit rot or corruption in stored blobs; passing a manually assembled byte slice; reading past a wrong offset because an earlier field was mis-sized.","solutions":["Verify buffer integrity with proto.Unmarshal before raw scanning.","Re-generate or re-fetch the message bytes from the source of truth.","Check that no earlier manual byte manipulation shifted offsets."],"exampleFix":"// before\nraw, _ := codec.GetRawProtoField(foreignBytes, 1)\n// after\nif err := proto.Unmarshal(data, &msg); err != nil { return err }\nraw, err := codec.GetRawProtoField(data, 1)","handlingStrategy":"validation","validationCode":"var probe pb.Event\nif err := proto.Unmarshal(data, &probe); err != nil {\n    return fmt.Errorf(\"malformed wire data: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"raw, err := codec.GetRawProtoField(data, fieldNum)\nif err != nil && strings.Contains(err.Error(), \"invalid field value\") {\n    return fmt.Errorf(\"corrupt field encoding: %w\", err)\n}","preventionTips":["Keep the data path proto-pure: no manual byte edits before extraction.","Confirm field numbers/wire types against the current .proto schema.","Test corruption detection with fuzzed inputs in CI."],"tags":["protobuf","wire-format","corrupt-data","varint"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"ee8197d91dd410f6592cb650a94c925ee6dc8bad","analyzedAt":"2026-09-06T09:30:15.973Z","contentChangedAt":"2026-09-06T09:30:15.973Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}