derp: prevent readFrame() from reading more than len(b) bytes.
@@ -138,7 +138,8 @@ func readFrame(br *bufio.Reader, maxSize uint32, b []byte) (t frameType, frameLe
if frameLen > maxSize {
return 0, 0, fmt.Errorf("frame header size %d exceeds reader limit of %d", frameLen, maxSize)
}
- n, err := io.ReadFull(br, b[:frameLen])
+
+ n, err := io.ReadFull(br, b[:minUint32(frameLen, uint32(len(b)))])
if err != nil {
return 0, 0, err
}
@@ -179,3 +180,10 @@ func minInt(a, b int) int {
}
return b
}
+
+func minUint32(a, b uint32) uint32 {
+ if a < b {
+ return a
+ }
+ return b
+}
