Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions buf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pq
import (
"bytes"
"encoding/binary"
"math"

"github.com/lib/pq/oid"
)
Expand Down Expand Up @@ -79,12 +80,18 @@ func (b *writeBuf) bytes(v []byte) {

func (b *writeBuf) wrap() []byte {
p := b.buf[b.pos:]
if len(p) > math.MaxUint32 {
panic("message too large")
}
binary.BigEndian.PutUint32(p, uint32(len(p)))
return b.buf
}

func (b *writeBuf) next(c byte) {
p := b.buf[b.pos:]
if len(p) > math.MaxUint32 {
panic("message too large")
}
binary.BigEndian.PutUint32(p, uint32(len(p)))
b.pos = len(b.buf) + 1
b.buf = append(b.buf, c, 0, 0, 0, 0)
Expand Down
4 changes: 4 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"errors"
"fmt"
"io"
"math"
"net"
"os"
"os/user"
Expand Down Expand Up @@ -820,6 +821,9 @@ func decideColumnFormats(
return colFmts, colFmtDataAllText
} else {
colFmtData = make([]byte, 2+len(colFmts)*2)
if len(colFmts) > math.MaxUint16 {
panic("too many columns")
}
binary.BigEndian.PutUint16(colFmtData, uint16(len(colFmts)))
for i, v := range colFmts {
binary.BigEndian.PutUint16(colFmtData[2+i*2:], uint16(v))
Expand Down
4 changes: 4 additions & 0 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"math"
"sync"
)

Expand Down Expand Up @@ -140,6 +141,9 @@ awaitCopyInResponse:
}

func (ci *copyin) flush(buf []byte) {
if len(buf)-1 > math.MaxUint32 {
panic("too many columns")
}
// set message length (without message identifier)
binary.BigEndian.PutUint32(buf[1:], uint32(len(buf)-1))

Expand Down