{"record":{"id":"34aeb7c5bc92dbd4","repo":"jackc/pgx","slug":"invalid-tsvector-binary-format-lexeme-d-position","errorCode":null,"errorMessage":"invalid tsvector binary format: lexeme %d positions: %w","messagePattern":"invalid tsvector binary format: lexeme (.+?) positions: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/tsvector.go","lineNumber":226,"sourceCode":"\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\n\t\ttsv.Lexemes[i] = lexeme\n\t}\n\n\tif err := r.Finish(); err != nil {\n\t\treturn fmt.Errorf(\"tsvector: %w\", err)\n\t}\n\ttsv.Valid = true\n\n\treturn scanner.ScanTSVector(tsv)\n}\n\nvar tsvectorLexemeReplacer = strings.NewReplacer(\n\t`\\`, `\\\\`,\n\t`'`, `\\'`,\n)","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/tsvector.go#L208-L244","documentation":"After reading the packed positions of lexeme %d in a binary tsvector, the reader errored (truncated position data). The allocation was bounded, but the message did not contain all declared positions.","triggerScenarios":"Thrown at pgtype/tsvector.go:226 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fail the scan; position data is incomplete","Verify the binary payload comes from a real PostgreSQL server","Check for truncation in transit"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}