Skip to content

Commit

Permalink
limit buffer usage
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Tolstov <[email protected]>
  • Loading branch information
vtolstov committed Jun 18, 2017
1 parent 1413d28 commit c8905c0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
7 changes: 1 addition & 6 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions example/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c8905c0

Please sign in to comment.