{"id":"492357f19cbfccce","repo":"jackc/pgx","slug":"invalid-tsvector-binary-format-lexeme-d-w","errorCode":null,"errorMessage":"invalid tsvector binary format: lexeme %d: %w","messagePattern":"invalid tsvector binary format: lexeme (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/tsvector.go","lineNumber":211,"sourceCode":"\t// Each lexeme carries at minimum a 1-byte NUL terminator and a 2-byte position count. This\n\t// bounds the up-front make() against a malicious server claiming a huge lexeme count in a\n\t// small message.\n\tentryCount := r.Count(3)\n\tif err := r.Err(); err != nil {\n\t\treturn fmt.Errorf(\"tsvector: %w\", err)\n\t}\n\n\tvar tsv TSVector\n\tif entryCount > 0 {\n\t\ttsv.Lexemes = make([]TSVectorLexeme, entryCount)\n\t}\n\n\tfor i := range entryCount {\n\t\tlexeme := TSVectorLexeme{Word: string(r.CString())}\n\n\t\tnumPositions := int(r.Uint16())\n\t\tif err := r.Err(); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid tsvector binary format: lexeme %d: %w\", i, err)\n\t\t}\n\n\t\t// Each packed position is weight (2 bits) | position (14 bits). numPositions came from a\n\t\t// uint16, so it cannot ask for an unreasonable allocation here.\n\t\tif numPositions > 0 {\n\t\t\tlexeme.Positions = make([]TSVectorPosition, numPositions)\n\t\t\tfor pos := range numPositions {\n\t\t\t\tpacked := r.Uint16()\n\t\t\t\tlexeme.Positions[pos] = TSVectorPosition{\n\t\t\t\t\tPosition: packed & 0x3FFF,\n\t\t\t\t\tWeight:   tsvectorWeightFromBinary(packed >> 14),\n\t\t\t\t}\n\t\t\t}\n\t\t\tif err := r.Err(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"invalid tsvector binary format: lexeme %d positions: %w\", i, err)\n\t\t\t}\n\t\t}\n","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/tsvector.go#L193-L229","documentation":"Error \"invalid tsvector binary format: lexeme %d: %w\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgtype/tsvector.go:211 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}