{"record":{"id":"9f413fd29f626c36","repo":"jackc/pgx","slug":"invalid-value-length-d-at-offset-d","errorCode":null,"errorMessage":"invalid value length %d at offset %d","messagePattern":"invalid value length (.+?) at offset (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pgio/read.go","lineNumber":189,"sourceCode":"\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\n\tlength := r.Int32()\n\tif r.err != nil {\n\t\treturn nil, false\n\t}\n\tif length == -1 {\n\t\treturn nil, true\n\t}\n\tif length < 0 {\n\t\tr.fail(fmt.Errorf(\"invalid value length %d at offset %d\", length, offset))\n\t\treturn nil, false\n\t}\n\treturn r.Bytes(int(length)), false\n}\n\n// Finish returns the first error encountered, or an error if unread bytes\n// remain. Decoders that must consume the entire source should end with Finish.\nfunc (r *Reader) Finish() error {\n\tif r.err != nil {\n\t\treturn r.err\n\t}\n\tif r.rp != len(r.s) {\n\t\treturn r.errTrailing()\n\t}\n\treturn nil\n}\n\nfunc (r *Reader) errTrailing() error {","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/internal/pgio/read.go#L171-L207","documentation":"Reader.Value read a value length that is negative but not the -1 NULL sentinel. Any length other than -1 must be non-negative; this indicates a malformed binary value field in the message.","triggerScenarios":"Thrown at internal/pgio/read.go:189 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the length field at the recorded offset in the raw message","Verify the encoder emits -1 for NULL and non-negative lengths otherwise","Treat as protocol corruption and drop the connection"],"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"}