{"id":"abae88d269924e9a","repo":"jackc/pgx","slug":"w-unterminated-string-at-offset-d","errorCode":null,"errorMessage":"%w: unterminated string at offset %d","messagePattern":"%w: unterminated string at offset (.+?)","errorType":"exception","errorClass":"ErrInsufficientBytes","httpStatus":null,"severity":"error","filePath":"internal/pgio/read.go","lineNumber":142,"sourceCode":"\t}\n\tif !r.need(n) {\n\t\treturn nil\n\t}\n\tb := r.s[r.rp : r.rp+n]\n\tr.rp += n\n\treturn b\n}\n\n// CString reads a NUL-terminated string, returning the bytes before the\n// terminator and consuming the terminator. The returned slice aliases the\n// source; it is not a copy.\nfunc (r *Reader) CString() []byte {\n\tif r.err != nil {\n\t\treturn nil\n\t}\n\ti := bytes.IndexByte(r.s[r.rp:], 0)\n\tif i < 0 {\n\t\tr.fail(fmt.Errorf(\"%w: unterminated string at offset %d\", ErrInsufficientBytes, r.rp))\n\t\treturn nil\n\t}\n\tb := r.s[r.rp : r.rp+i]\n\tr.rp += i + 1\n\treturn b\n}\n\n// Count reads an int32 element count and validates it against the remaining\n// bytes: the count must be non-negative, and since each element occupies at\n// least minElemSize bytes, count*minElemSize must not exceed the remaining\n// message. This bounds allocations sized from the count against a malicious\n// or corrupt message claiming a huge count. Returns 0 on any failure.\nfunc (r *Reader) Count(minElemSize int) int {\n\toffset := r.rp\n\tcount := int(r.Int32())\n\tif r.err != nil {\n\t\treturn 0\n\t}","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/internal/pgio/read.go#L124-L160","documentation":"Error \"%w: unterminated string at offset %d\" thrown in jackc/pgx.","triggerScenarios":"Thrown at internal/pgio/read.go:142 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}