Skip to content

Commit

Permalink
Fix: pgtype.Bits makes copy of data from read buffer
Browse files Browse the repository at this point in the history
It was taking a reference. This would cause the data to be corrupted by
future reads.

fixes #1909
  • Loading branch information
jackc committed Feb 23, 2024
1 parent 5c63f64 commit 654dcab
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pgtype/bits.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ func (scanPlanBinaryBitsToBitsScanner) Scan(src []byte, dst any) error {

bitLen := int32(binary.BigEndian.Uint32(src))
rp := 4
buf := make([]byte, len(src[rp:]))
copy(buf, src[rp:])

return scanner.ScanBits(Bits{Bytes: src[rp:], Len: bitLen, Valid: true})
return scanner.ScanBits(Bits{Bytes: buf, Len: bitLen, Valid: true})
}

type scanPlanTextAnyToBitsScanner struct{}
Expand Down

0 comments on commit 654dcab

Please sign in to comment.