{"id":"1540d329beed8e6e","repo":"jackc/pgx","slug":"invalid-element-count-d-at-offset-d","errorCode":null,"errorMessage":"invalid element count %d at offset %d","messagePattern":"invalid element count (.+?) at offset (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pgio/read.go","lineNumber":162,"sourceCode":"\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}\n\tif count < 0 {\n\t\tr.fail(fmt.Errorf(\"invalid element count %d at offset %d\", count, offset))\n\t\treturn 0\n\t}\n\tif minElemSize < 1 {\n\t\tminElemSize = 1\n\t}\n\tif count > r.Remaining()/minElemSize {\n\t\tr.fail(fmt.Errorf(\"element count %d at offset %d exceeds %d remaining bytes\", count, offset, r.Remaining()))\n\t\treturn 0\n\t}\n\treturn count\n}\n\n// Value reads an int32 length followed by that many bytes — the standard\n// PostgreSQL binary representation of a value. A length of -1 means NULL and\n// returns (nil, true). Any other negative length is an error. The returned\n// slice aliases the source; null is only meaningful if Err returns nil.\nfunc (r *Reader) Value() (data []byte, null bool) {\n\toffset := r.rp","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/internal/pgio/read.go#L144-L180","documentation":"Error \"invalid element count %d at offset %d\" thrown in jackc/pgx.","triggerScenarios":"Thrown at internal/pgio/read.go:162 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}