Commit c1da7072 authored by Damian Gryski's avatar Damian Gryski

decoder: avoid problems with short reads

parent 43c00601
...@@ -411,7 +411,10 @@ func (d *Decoder) loadBinString() error { ...@@ -411,7 +411,10 @@ func (d *Decoder) loadBinString() error {
func (d *Decoder) loadShortBinString() error { func (d *Decoder) loadShortBinString() error {
b, _ := d.r.ReadByte() b, _ := d.r.ReadByte()
s := make([]byte, b) s := make([]byte, b)
d.r.Read(s) _, err := io.ReadFull(d.r, s)
if err != nil {
return err
}
d.push(string(s)) d.push(string(s))
return nil return nil
} }
...@@ -586,9 +589,8 @@ func (d *Decoder) loadSetItems() error { ...@@ -586,9 +589,8 @@ func (d *Decoder) loadSetItems() error {
} }
func (d *Decoder) binFloat() error { func (d *Decoder) binFloat() error {
f := make([]byte, 8) var u uint64
d.r.Read(f) binary.Read(d.r, binary.BigEndian, &u)
u := binary.BigEndian.Uint64(f)
d.stack = append(d.stack, math.Float64frombits(u)) d.stack = append(d.stack, math.Float64frombits(u))
return nil return nil
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment