Skip to content

Fix a crash when initialDirectory contains special characters on Linux#1963

Open
TechnicJelle wants to merge 1 commit intomiguelpruivo:masterfrom
TechnicJelle:fix-linux-initialDirectory-crash
Open

Fix a crash when initialDirectory contains special characters on Linux#1963
TechnicJelle wants to merge 1 commit intomiguelpruivo:masterfrom
TechnicJelle:fix-linux-initialDirectory-crash

Conversation

@TechnicJelle
Copy link

Today, I was testing my Flutter program, and happened to select a directory that has a non-ASCII character in it.

Specifically, this character: گ (Arabic letter Kaf with line, used for /g/)

The selecting part went okay, and I got the result back just fine.
However, my application stores the resulting path, and uses that as the initialDirectory for the next pick.
There, it would keep crashing:

Stacktrace
Performing hot restart...
Syncing files to device Linux...
Restarted application in 547ms.
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: 'package:dbus/src/dbus_value.dart': Failed assertion: line 151 pos 16: 'value >= 0 && value <= 255': Byte must be in range [0, 255]
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:67:4)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:49:5)
#2      new DBusByte (package:dbus/src/dbus_value.dart:151:16)
#3      new DBusArray.byte.<anonymous closure> (package:dbus/src/dbus_value.dart:919:51)
#4      MappedListIterable.elementAt (dart:_internal/iterable.dart:442:31)
#5      ListIterator.moveNext (dart:_internal/iterable.dart:371:26)
#6      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:194:27)
#7      new _GrowableList.of (dart:core-patch/growable_array.dart:154:28)
#8      new List.of (dart:core-patch/array_patch.dart:39:18)
#9      ListIterable.toList (dart:_internal/iterable.dart:224:7)
#10     new DBusArray (package:dbus/src/dbus_value.dart:893:29)
#11     new DBusArray.byte (package:dbus/src/dbus_value.dart:918:12)
#12     FilePickerLinux.getDirectoryPath (package:file_picker/src/linux/file_picker_linux.dart:112:39)
#13     PathPickerButton.build.<anonymous closure> (package:bluemap_gui/project_view/configs/views/base.dart:117:60)
#14     _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1224:21)
#15     GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:345:24)
#16     TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:758:11)
#17     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:383:5)
#18     BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:353:7)
#19     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:173:27)
#20     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:532:20)
#21     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:498:22)
#22     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:473:11)
#23     GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:437:7)
#24     GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:394:5)
#25     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:341:7)
#26     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:308:9)
#27     _invoke1 (dart:ui/hooks.dart:372:13)
#28     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:467:7)
#29     _dispatchPointerDataPacket (dart:ui/hooks.dart:307:31)

The exact code it was crashing on was this:

List<int> tmp = [];
for (var i = 0; i < initialDirectory.length; i++) {
  tmp.add(initialDirectory[i].codeUnitAt(0));
}
tmp.add(0);
DBusArray directory = DBusArray.byte(tmp);

In that last line is an assert that ensures the ints of the tmp list are actually bytes, and not way too high.

However, that special character results in the value being 1711, as you can see in this screenshot of the debugger:
image

The full contents of the tmp list image image

And so, together with a friend, we concluded that the way that the tmp list is being constructed isn't completely proper.

This PR fixes that, by using Dart's built-in UTF-8 encoder to convert the string to a byte array.

I verified with the DBus docs, and DBus String are indeed only allowed to be UTF-8:

I have tested this in my own program, and it does solve the issue.

Here's a pair of (somewhat crappy) videos demonstrating the issue and that the fix works:

The issue:

Peek.2026-03-10.21-41.mp4

The fix:

Peek.2026-03-10.21-35.mp4

This prevents the file_picker from crashing when initialDirectory contains any special characters
@TechnicJelle
Copy link
Author

I forked this from the tag v10.3.10, by the way.
Hope that's okay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant