Skip to content

Issues with MAX_INVITATION_TEXT_LENGTH

Although we check for and trim (forum) invitation messages to MAX_INVITATION_TEXT_LENGTH, I am able to trigger a FormatException when using text copied from https://gutenberg.ca/ebooks/huxleya-bravenewworld/huxleya-bravenewworld-00-h.html, with the text provided to Briar core being too long:

12:06:53.175 [pool-1-thread-55] INFO  o.b.b.s.v.ValidationManagerImpl - org.briarproject.bramble.api.sync.InvalidMessageException: org.briarproject.bramble.api.FormatException
org.briarproject.bramble.api.sync.InvalidMessageException: org.briarproject.bramble.api.FormatException
	at org.briarproject.bramble.api.client.BdfMessageValidator.validateMessage(BdfMessageValidator.java:57)
	at org.briarproject.bramble.sync.validation.ValidationManagerImpl.validateMessage(ValidationManagerImpl.java:240)
	at org.briarproject.bramble.sync.validation.ValidationManagerImpl.lambda$validateMessageAsync$4(ValidationManagerImpl.java:225)
	at org.briarproject.bramble.PoliteExecutor.lambda$execute$0(PoliteExecutor.java:57)
	at org.briarproject.bramble.TimeLoggingExecutor.lambda$execute$0(TimeLoggingExecutor.java:38)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.briarproject.bramble.api.FormatException: null
	at org.briarproject.bramble.util.ValidationUtils.checkLength(ValidationUtils.java:20)
	at org.briarproject.briar.sharing.SharingValidator.validateInviteMessage(SharingValidator.java:70)
	at org.briarproject.briar.sharing.SharingValidator.validateMessage(SharingValidator.java:46)
	at org.briarproject.bramble.api.client.BdfMessageValidator.validateMessage(BdfMessageValidator.java:53)
	... 7 common frames omitted

This error is not visible to the user, but the message is still added to the local database.

Using text from https://ctext.org/huainanzi/dao-ying-xun with Chinese characters, I was able to trigger a different error:

12:05:20.359 [pool-2-thread-54] WARN  o.b.b.d.threading.BriarExecutorsImpl - Unhandled exception in database executor
java.lang.IllegalArgumentException: null
	at org.briarproject.bramble.sync.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:41)
	at org.briarproject.briar.sharing.MessageEncoderImpl.encodeInviteMessage(MessageEncoderImpl.java:120)
	at org.briarproject.briar.sharing.ProtocolEngineImpl.sendInviteMessage(ProtocolEngineImpl.java:143)
	at org.briarproject.briar.sharing.ProtocolEngineImpl.onLocalInvite(ProtocolEngineImpl.java:113)
	at org.briarproject.briar.sharing.ProtocolEngineImpl.onInviteAction(ProtocolEngineImpl.java:98)
	at org.briarproject.briar.sharing.SharingManagerImpl.sendInvitation(SharingManagerImpl.java:298)
	at org.briarproject.briar.desktop.forums.sharing.ForumSharingViewModel$shareForum$1.invoke(ForumSharingViewModel.kt:146)
	at org.briarproject.briar.desktop.forums.sharing.ForumSharingViewModel$shareForum$1.invoke(ForumSharingViewModel.kt:142)
	at org.briarproject.briar.desktop.threading.BriarExecutorsImpl.onDbThreadWithTransaction$lambda$1(BriarExecutorsImpl.kt:68)
	at org.briarproject.bramble.TimeLoggingExecutor.lambda$execute$0(TimeLoggingExecutor.java:38)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

In that case, the message was neither sent not added to the local database.

The issue might be related to the fact that briar core checks the message length on utf8 bytes, while the UI trims according to String::length.