vnc2video icon indicating copy to clipboard operation
vnc2video copied to clipboard

Sometimes app crashes

Open DeadNumbers opened this issue 5 years ago • 4 comments

Hi! I'm tested this code on Arch Linux, Gnome and Vino (https://wiki.gnome.org/Projects/Vino). Code from examples/client

package main

import (
	"context"
	"fmt"
	"net"
	"runtime"
	"time"

	vnc "github.com/amitbet/vnc2video"
	"github.com/amitbet/vnc2video/logger"
)

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	nc, err := net.DialTimeout("tcp", "127.0.0.1:5900", 60*time.Second)
	if err != nil {
		logger.Fatalf("Error connecting to VNC host. %v", err)
	}

	logger.Tracef("starting up the client, connecting to: %s", "127.0.0.1:5900")
	cchServer := make(chan vnc.ServerMessage)
	cchClient := make(chan vnc.ClientMessage)
	errorCh := make(chan error)

	ccfg := &vnc.ClientConfig{
		SecurityHandlers: []vnc.SecurityHandler{
			&vnc.ClientAuthVNC{Password: []byte("12345")},
			&vnc.ClientAuthNone{},
		},
		DrawCursor:      true,
		PixelFormat:     vnc.PixelFormat32bit,
		ClientMessageCh: cchClient,
		ServerMessageCh: cchServer,
		Messages:        vnc.DefaultServerMessages,
		Encodings: []vnc.Encoding{
			&vnc.RawEncoding{},
		},
		ErrorCh: errorCh,
	}

	cc, err := vnc.Connect(context.Background(), nc, ccfg)
	if err != nil {
		logger.Fatalf("Error negotiating connection to VNC host. %v", err)
	}
	fmt.Println(string(cc.DesktopName()))
}

Traceback

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x5129f6]

goroutine 8 [running]:
github.com/amitbet/vnc2video.(*VncCanvas).RemoveCursor(0x0, 0xc0000727e0, 0xc000044f07)
	github.com/amitbet/vnc2video/encoding_util.go:61 +0x26
github.com/amitbet/vnc2video.(*DefaultClientMessageHandler).Handle.func2(0xc00001c550, 0x5a4e80, 0xc000136500, 0xc0000126d0, 0xc000134000, 0xc0000727e0)
	github.com/amitbet/vnc2video/client.go:303 +0x28a
created by github.com/amitbet/vnc2video.(*DefaultClientMessageHandler).Handle
	github.com/amitbet/vnc2video/client.go:285 +0x2b8

Sometimes app print desktop name, but sometimes app crashed. изображение

DeadNumbers avatar Feb 27 '20 14:02 DeadNumbers

Any ideas?

DeadNumbers avatar Mar 07 '20 18:03 DeadNumbers

well, it looks like there is some nil pointer in there :) these situations really need a debugger attached.. remote advice according to an error won't do a lot of good. Would love to be of more help, if you have more info..

I never tested this on archlinux, and more importantly I don't know which vnc server this is working with. Sometimes they use some messages that I haven't programmed in, which makes the decoder derail (this is a binary stream after all), and sometimes there can be a message that sends a legit payload that I have not planned for. In VncProxy I think I have worked out most of these kinks, but this project was never in production. if you manage to debug it, it'll be glad to merge your code back in.

amitbet avatar Mar 21 '20 01:03 amitbet

I see Vino is a VNC-Server... I used tight to program this - so that would be a more compatible option if you don't have the time to debug.

amitbet avatar Mar 21 '20 02:03 amitbet

@DeadNumbers

It seems that sometimes DefaultClientMessageHandler is called before the canvas is initialized. https://github.com/amitbet/vnc2video/blob/9d50b9dab1d92afd6c71ca5ccc5157135c121428/client.go#L37-L49

DefaultClientMessageHandler is set up and started in line 38 and canvas is set up in line 48.

See #14 for my proposed fix.

gyuchang avatar May 08 '20 06:05 gyuchang