Skip to content

[DragAndDrop] panic when dropping non-file objects #3596

@Alpa-1

Description

@Alpa-1

Description

Summary

A panic occurs when dropping a non-file object into the webview - for example a string or browser tab.

Details

internal/frontend/desktop/windows/frontend.go

on the call:

_file, err := objs.GetValueAtIndex(i)

a nil value is returned with no error. Presumably because no value is actually available.

However this nil value is then used subsequently:

file := (*edge.ICoreWebView2File)(unsafe.Pointer(_file))
defer file.Release()

Upon Release() the program panics.


panic: runtime error: invalid memory address or nil pointer dereference
	panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0xb8309e]

goroutine 1 [running, locked to thread]:
github.com/wailsapp/go-webview2/pkg/edge.(*ICoreWebView2File).Release(0x0)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/go-webview2@v1.0.10/pkg/edge/ICoreWebView2File.go:25 +0x1e
panic({0xec12e0?, 0x1979990?})
	C:/Program Files/Go/src/runtime/panic.go:770 +0x136
github.com/wailsapp/go-webview2/pkg/edge.(*ICoreWebView2File).GetPath(0x0)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/go-webview2@v1.0.10/pkg/edge/ICoreWebView2File.go:31 +0x103
github.com/wailsapp/wails/v2/internal/frontend/desktop/windows.(*Frontend).processMessageWithAdditionalObjects(0xc00003a200, {0xc00001eaf8, 0x11}, 0x1e6c00308000, 0x1e6c002d0a80)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/wails/v2@v2.9.1/internal/frontend/desktop/windows/frontend.go:746 +0x60e
github.com/wailsapp/go-webview2/pkg/edge.(*Chromium).MessageReceived(0xc0000dc6c0, 0x1e6c00308000, 0x1e6c002d0a80)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/go-webview2@v1.0.10/pkg/edge/chromium.go:342 +0x3ee
github.com/wailsapp/go-webview2/pkg/edge._ICoreWebView2WebMessageReceivedEventHandlerInvoke(0xc000009140, 0x1e6c00308000, 0x1e6c002d0a80)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/go-webview2@v1.0.10/pkg/edge/ICoreWebView2WebMessageReceivedEventHandler.go:28 +0x38
syscall.SyscallN(0x7ffd344fe1e0, {0xc000712610?, 0x1, 0x1c763c61c28?})
	C:/Program Files/Go/src/runtime/syscall_windows.go:544 +0x11d
[...]

To Reproduce

  1. Enable DragAndDrop
  2. Add a drop target on the frontend --wails-drop-target
  3. Register a callback
OnFileDrop((x,y,f) => { console.log(f) }, true)
  1. Drop a Browser Tab onto the element

Expected behaviour

Dropped non-file object should be disregarded

Screenshots

No response

Attempted Fixes

A simple nil check has alleviated the issue:

_file, err := objs.GetValueAtIndex(i)
if err != nil {
        f.logger.Error("cannot get value at %d : %s", i, err.Error())
	return
}

if _file == nil {
	f.logger.Warning("object at %d is not a file", i)
	continue
}

file := (*edge.ICoreWebView2File)(unsafe.Pointer(_file))
defer file.Release()

System Details

# Wails
Version | v2.9.1

# System
┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 10 Enterprise                                                            |
| Version      | 2009 (Build: 19045)                                                              |
| ID           | 22H2                                                                             |
| Go Version   | go1.22.1                                                                         |
| Platform     | windows                                                                          |
| Architecture | amd64                                                                            |
| CPU          | AMD Ryzen 7 PRO 4750U with Radeon Graphics                                       |
| GPU          | AMD Radeon(TM) Graphics (Advanced Micro Devices, Inc.) - Driver: 31.0.21024.5005 |
| Memory       | 16GB                                                                             |
└─────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version       |
| WebView2   | N/A          | Installed | 126.0.2592.87 |
| Nodejs     | N/A          | Installed | 20.12.1       |
| npm        | N/A          | Installed | 10.5.0        |
| *upx       | N/A          | Installed | upx 4.0.1     |
| *nsis      | N/A          | Available |               |
└─────────────── * - Optional Dependency ───────────────┘

# Diagnosis
Optional package(s) installation details:
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

 SUCCESS  Your system is ready for Wails development!

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions