bluey icon indicating copy to clipboard operation
bluey copied to clipboard

Android bluey doesn't handle invalid advertisement strings

Open qdot opened this issue 2 years ago • 1 comments

Ran into a device we couldn't see on btleplug, decided to try bluey. Luckily you have more error logging than I did. :)

We have a device that puts an invalid UTF-8 string in advertisements. On Windows/macOS/iOS/Linux, apparently this is handled below the OS APIs. However on Android, both bluey and btleplug get back the raw buffer. bluey will throw an error trying to parse this advertisement.

I'm fixing this in btleplug but calling String::from_utf8_lossy then filtering out the replacement character, like so:

String::from_utf8_lossy(device_name_str.to_bytes())
                        .chars()
                        .filter(|&c| c != '\u{fffd}')
                        .collect()

Dunno if you're interested in doing the same (or if you're even still working on this), but just in case you run into it, thought I'd report it.

qdot avatar Nov 19 '23 00:11 qdot

Ran into a device we couldn't see on btleplug, decided to try bluey. Luckily you have more error logging than I did. :)

We have a device that puts an invalid UTF-8 string in advertisements. On Windows/macOS/iOS/Linux, apparently this is handled below the OS APIs. However on Android, both bluey and btleplug get back the raw buffer. bluey will throw an error trying to parse this advertisement.

I'm fixing this in btleplug but calling String::from_utf8_lossy then filtering out the replacement character, like so:

String::from_utf8_lossy(device_name_str.to_bytes())
                        .chars()
                        .filter(|&c| c != '\u{fffd}')
                        .collect()

Dunno if you're interested in doing the same (or if you're even still working on this), but just in case you run into it, thought I'd report it.

Hey, yeah I can look at folding a similar fix into Bluey, thanks for the heads up!

As you no doubt saw, I haven't been working on Bluey actively recently though have had a few things in mind recently that might lead me to pick it back up.

Glad Bluey was useful to you as a point of reference at least!

rib avatar Nov 19 '23 19:11 rib