go-flutter-desktop / go-flutter

Flutter on Windows, MacOS and Linux - based on Flutter Embedding, Go and GLFW.
https://hover.build/
BSD 3-Clause "New" or "Revised" License
5.86k stars 282 forks source link

slice bounds out of range in text-input.go #460

Closed kiasaki closed 4 years ago

kiasaki commented 4 years ago

Hover doctor

$ hover doctor
hover: Hover version v0.41.5 running on darwin
hover: Sharing flutter version
Flutter 1.19.0-1.0.pre • channel dev • https://github.com/flutter/flutter.git
Framework • revision 456d80b9dd (3 weeks ago) • 2020-05-11 11:45:03 -0400
Engine • revision d96f962ca2
Tools • Dart 2.9.0 (build 2.9.0-7.0.dev 092ed38a87)
hover: Flutter engine commit: https://github.com/flutter/engine/commit/d96f962ca21a104b08836f34814eb6b267937511
hover: ⚠ The go-flutter project tries to stay compatible with the beta channel of Flutter.
hover: ⚠     It's advised to use the beta channel: `flutter channel beta`
hover: Finding out the C compiler version
Apple clang version 11.0.3 (clang-1103.0.32.29)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
hover: Sharing the content of go.mod
module telefuel/go

go 1.14

require (
        github.com/3d0c/gmf v0.0.0-20190724130615-f4b5acb7db5c
        github.com/go-flutter-desktop/go-flutter v0.41.0
        github.com/go-flutter-desktop/plugins/image_picker v0.1.5
        github.com/go-flutter-desktop/plugins/path_provider v0.4.0
        github.com/go-flutter-desktop/plugins/url_launcher v0.1.2
        github.com/go-flutter-desktop/plugins/video_player v0.0.3
        github.com/pkg/errors v0.9.1
        github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
)
hover: Sharing the content of hover.yaml
application-name: Telefuel
executable-name: ""
package-name: ""
license: ""
target: lib/main_desktop.dart
branch: ""
cache-path: ""
opengl: ""
engine-version: ""
hover: Sharing the content of go/cmd
go/cmd/main.go  go/cmd/options.go       go/cmd/plugin.go        go/cmd/video_player.go

Error output

The issue seems to be caused here: go-flutter@v0.41.0/text-input.go:223

My app exited with the following after clearing the text in a TextController:

$ hover run                                              
hover: ⚠ The go-flutter project tries to stay compatible with the beta channel of Flutter.
hover: ⚠     It's advised to use the beta channel: `flutter channel beta`
hover: Building flutter bundle
hover: Using engine from cache
hover: Compiling 'go-flutter' and plugins
hover: Successfully compiled
hover: Build finished, starting app...
hover: Running text_input_error in debug mode
go-flutter: WARNING error creating the resource window: VersionUnavailable: NSGL: Failed to create OpenGL context
[ERROR:flutter/shell/platform/embedder/embedder_surface_gl.cc(107)] Could not create a resource context for async texture uploads. Expect degraded performance. Set a valid make_resource_current callback on FlutterOpenGLRendererConfig.
[ERROR:flutter/shell/platform/embedder/embedder_surface_gl.cc(107)] Could not create a resource context for async texture uploads. Expect degraded performance. Set a valid make_resource_current callback on FlutterOpenGLRendererConfig.
flutter: Observatory listening on http://127.0.0.1:50300/
hover: Connecting hover to 'text_input_error' for hot reload
Waiting for Flutter test device to report its views...               9ms
Lost connection to device.                                              
Syncing files to device Flutter test device...                         ⣟panic: runtime error: slice bounds out of range [:-1]

goroutine 1 [running, locked to thread]:
github.com/go-flutter-desktop/go-flutter.(*textinputPlugin).addText(0x43a8ec0, 0xc000000061)
        /Users/kiasaki/code/go/pkg/mod/github.com/go-flutter-desktop/go-flutter@v0.41.0/text-input.go:223 +0x34e
github.com/go-flutter-desktop/go-flutter.(*textinputPlugin).glfwCharCallback(0x43a8ec0, 0xc000100000, 0x61)
        /Users/kiasaki/code/go/pkg/mod/github.com/go-flutter-desktop/go-flutter@v0.41.0/text-input.go:148 +0x55
github.com/go-gl/glfw/v3.3/glfw.goCharCB(0x6975b90, 0x61)
        /Users/kiasaki/code/go/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20200420212212-258d9bec320e/input.go:365 +0x51
github.com/go-gl/glfw/v3.3/glfw._cgoexpwrap_9b801eba25a4_goCharCB(0x6975b90, 0x61)
        _cgo_gotypes.go:2612 +0x33
github.com/go-gl/glfw/v3.3/glfw._Cfunc_glfwWaitEventsTimeout(0x3f9999999999999a)
        _cgo_gotypes.go:2437 +0x41
github.com/go-gl/glfw/v3.3/glfw.WaitEventsTimeout(0x3f9999999999999a)
        /Users/kiasaki/code/go/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20200420212212-258d9bec320e/window.go:994 +0x2d
github.com/go-flutter-desktop/go-flutter.(*Application).Run.func12(0x3f9999999999999a)
        /Users/kiasaki/code/go/pkg/mod/github.com/go-flutter-desktop/go-flutter@v0.41.0/application.go:351 +0x2d
github.com/go-flutter-desktop/go-flutter.(*EventLoop).WaitForEvents(0xc0000921e0, 0x422d010)
        /Users/kiasaki/code/go/pkg/mod/github.com/go-flutter-desktop/go-flutter@v0.41.0/event-loop.go:120 +0x61b
github.com/go-flutter-desktop/go-flutter.(*Application).Run(0xc0000fc000, 0x0, 0x0)
        /Users/kiasaki/code/go/pkg/mod/github.com/go-flutter-desktop/go-flutter@v0.41.0/application.go:350 +0x11c7
github.com/go-flutter-desktop/go-flutter.Run(0xc0000ca120, 0x3, 0x4, 0x3, 0xc00005df40)
        /Users/kiasaki/code/go/pkg/mod/github.com/go-flutter-desktop/go-flutter@v0.41.0/application.go:26 +0x4d
main.main()
        /Users/kiasaki/code/repos/tmp/text_input_error/go/cmd/main.go:24 +0x188
hover: App 'text_input_error' exited with error: exit status 2

Reproducing

I was able to reproduce the error running https://gist.github.com/kiasaki/79a296498ff48e8cc2e65e46d337cd4a

Typing a bit and then quickly clicking that reset floating action button

kiasaki commented 4 years ago

I could write a PR with some kind of bounds checking but I'm not familiar enough with the problem space to know if that should be the fix of some more digging is needed to fix the problem at the source.

pchampio commented 4 years ago

Fixed in go-flutter v0.41.1 please hover bumpversion. Thanks for reporting this issue!

kiasaki commented 4 years ago

Amazing! Thanks for that :D