limit buffer usage
Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
parent
1413d28267
commit
c8905c0ea9
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
6
image.go
6
image.go
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user