Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android bluey doesn't handle invalid advertisement strings #1

Open
qdot opened this issue Nov 19, 2023 · 1 comment
Open

Android bluey doesn't handle invalid advertisement strings #1

qdot opened this issue Nov 19, 2023 · 1 comment

Comments

@qdot
Copy link

qdot commented Nov 19, 2023

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.

@rib
Copy link
Owner

rib commented Nov 19, 2023

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!

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

No branches or pull requests

2 participants