Skip to content

Commit e9e666a

Browse files
authored
msgp: fuzz test: fix overflow on 32-bit systems (#412)
On 32-bit systems, int(sz) can yield a negative value, which in turn leads to us passing a negative value to fwd.Reader.Next. (See philhofer/fwd#36.) The simplest fix here is just to check that the conversion doesn't yield a negative value.
1 parent 924e018 commit e9e666a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

msgp/read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (m *Reader) CopyNext(w io.Writer) (int64, error) {
175175
// Opportunistic optimization: if we can fit the whole thing in the m.R
176176
// buffer, then just get a pointer to that, and pass it to w.Write,
177177
// avoiding an allocation.
178-
if int(sz) <= m.R.BufferSize() {
178+
if int(sz) >= 0 && int(sz) <= m.R.BufferSize() {
179179
var nn int
180180
var buf []byte
181181
buf, err = m.R.Next(int(sz))

0 commit comments

Comments
 (0)