jackc/pgx · error
invalid element count %d at offset %d
Error message
invalid element count %d at offset %d
What it means
Error "invalid element count %d at offset %d" thrown in jackc/pgx.
Source
Thrown at internal/pgio/read.go:162
}
b := r.s[r.rp : r.rp+i]
r.rp += i + 1
return b
}
// Count reads an int32 element count and validates it against the remaining
// bytes: the count must be non-negative, and since each element occupies at
// least minElemSize bytes, count*minElemSize must not exceed the remaining
// message. This bounds allocations sized from the count against a malicious
// or corrupt message claiming a huge count. Returns 0 on any failure.
func (r *Reader) Count(minElemSize int) int {
offset := r.rp
count := int(r.Int32())
if r.err != nil {
return 0
}
if count < 0 {
r.fail(fmt.Errorf("invalid element count %d at offset %d", count, offset))
return 0
}
if minElemSize < 1 {
minElemSize = 1
}
if count > r.Remaining()/minElemSize {
r.fail(fmt.Errorf("element count %d at offset %d exceeds %d remaining bytes", count, offset, r.Remaining()))
return 0
}
return count
}
// Value reads an int32 length followed by that many bytes — the standard
// PostgreSQL binary representation of a value. A length of -1 means NULL and
// returns (nil, true). Any other negative length is an error. The returned
// slice aliases the source; null is only meaningful if Err returns nil.
func (r *Reader) Value() (data []byte, null bool) {
offset := r.rpView on GitHub (pinned to ec1a0befd2)
When it happens
Trigger: Thrown at internal/pgio/read.go:162 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04).
Data as JSON: /data/errors/1540d329beed8e6e.json.
Report an issue: GitHub.