limit buffer usage

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Василий Толстов 2017-06-18 21:01:01 +03:00
parent 1413d28267
commit c8905c0ea9
4 changed files with 10 additions and 14 deletions

View File

@ -244,16 +244,11 @@ func (enc *TightPngEncoding) Read(c Conn, rect *Rectangle) error {
cmp := enc.TightCC.Compression
switch cmp {
case TightCompressionPNG:
buf := bytes.NewBuffer(nil)
l, err := readTightLength(c)
if err != nil {
return err
}
_, err = io.CopyN(buf, c, int64(l))
if err != nil {
return err
}
enc.Image, err = png.Decode(buf)
enc.Image, err = png.Decode(io.LimitReader(c, int64(l)))
if err != nil {
return err
}

View File

@ -4,11 +4,17 @@ import (
"context"
"log"
"net"
"net/http"
_ "net/http/pprof"
vnc "github.com/vtolstov/go-vnc"
)
func main() {
go func() {
log.Println(http.ListenAndServe(":6060", nil))
}()
ln, err := net.Listen("tcp", ":5900")
if err != nil {
log.Fatalf("Error listen. %v", err)

View File

@ -114,6 +114,7 @@ func colorsToImage(x, y, width, height uint16, colors []Color) *image.RGBA64 {
// Marshal implements the Marshaler interface.
func (r *Rectangle) Write(c Conn) error {
var err error
if err = binary.Write(c, binary.BigEndian, r.X); err != nil {
return err
@ -131,10 +132,7 @@ func (r *Rectangle) Write(c Conn) error {
return err
}
if err := r.Enc.Write(c, r); err != nil {
return err
}
return c.Flush()
return r.Enc.Write(c, r)
}
func (r *Rectangle) Read(c Conn) error {

View File

@ -416,10 +416,7 @@ func (*Bell) Read(c Conn) (ServerMessage, error) {
}
func (msg *Bell) Write(c Conn) error {
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
return err
}
return c.Flush()
return binary.Write(c, binary.BigEndian, msg.Type())
}
type SetColorMapEntries struct {