eclipse-paho / eclipse-paho/paho.mqtt.java

java.lang.IllegalArgumentException: Invalid UTF-8 char: any more "forgiveness" possible?

Open
#996 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
919
PR merge metrics
No merged PRs in 30d

Description

Please fill out the form below before submitting, thank you!

- [x] Bug exists Release Version 1.2.5 ( Master Branch)
- [ ] Bug exists in MQTTv3 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
- [ ] Bug exists in MQTTv5 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)

```
STACK_TRACE=java.lang.IllegalArgumentException: Invalid UTF-8 char: [0]
at org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage.validateUTF8String(MqttWireMessage.java:407)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage.decodeUTF8(MqttWireMessage.java:365)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttPublish.(MqttPublish.java:64)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage.createWireMessage(MqttWireMessage.java:207)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage.createWireMessage(MqttWireMessage.java:182)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:119)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:137)
at java.lang.Thread.run(Thread.java:1012)
```

I use this PAHO client very happily, but now a customer got the message above. This might be a valid cause for an exception, but I don't have a change to "ignore" this crash in my Android app, so the user needs to re-install the app to get rid of the MQTT publishes he configured in my app as they will lead to the crash immediately after startup.

Is there a way to make the client code more "relaxed" about other clients publishing bad message texts to the MQTT server (I have not yet found where the code "0" is, but I guess it's a null terminator at the end of the string, which is included in the text - I don't know much about the inner format of MQTT messages and whether that's likely, but my C++ knowledge with 0-terminated strings forces that guess ;)).

A more tolerant client could help, or a way to "catch" such an event and allow the app to continue without crashing in a thread I did not create. It's OK to close the comm, of course.

I have read

> The character data in a UTF-8 encoded string MUST be well-formed UTF-8 as defined by the Unicode specification [Unicode] and restated in RFC 3629 [RFC3629]. In particular this data MUST NOT include encodings of code points between U+D800 and U+DFFF. If a Server or Client receives a Control Packet containing ill-formed UTF-8 it MUST close the Network Connection [MQTT-1.5.3-1].

so maybe the way to go is to include an option to be able to ignore the exception and become informed by some clientState event?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.