mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Raise MAX_CONTENT_TYPE_BYTES to 80, lower MAX_PRIVATE_MESSAGE_TEXT_LENGTH.
In case we ever want to send "application/vnd.openxmlformats-officedocument.wordprocessingml.document" attachments.
This commit is contained in:
@@ -11,7 +11,7 @@ public interface MediaConstants {
|
|||||||
/**
|
/**
|
||||||
* The maximum length of an attachment's content type in UTF-8 bytes.
|
* The maximum length of an attachment's content type in UTF-8 bytes.
|
||||||
*/
|
*/
|
||||||
int MAX_CONTENT_TYPE_BYTES = 50;
|
int MAX_CONTENT_TYPE_BYTES = 80;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum allowed size of image attachments.
|
* The maximum allowed size of image attachments.
|
||||||
|
|||||||
@@ -7,7 +7,17 @@ public interface MessagingConstants {
|
|||||||
/**
|
/**
|
||||||
* The maximum length of a private message's text in UTF-8 bytes.
|
* The maximum length of a private message's text in UTF-8 bytes.
|
||||||
*/
|
*/
|
||||||
int MAX_PRIVATE_MESSAGE_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
int MAX_PRIVATE_MESSAGE_TEXT_LENGTH = MAX_MESSAGE_BODY_LENGTH - 2048;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum length of an incoming private message's text in UTF-8 bytes.
|
||||||
|
* This is higher than MAX_PRIVATE_MESSAGE_TEXT_LENGTH for compatibility
|
||||||
|
* with older peers.
|
||||||
|
* <p>
|
||||||
|
* TODO: Remove after a reasonable migration period (added 2021-03-12).
|
||||||
|
*/
|
||||||
|
int MAX_PRIVATE_MESSAGE_INCOMING_TEXT_LENGTH =
|
||||||
|
MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of attachments per private message.
|
* The maximum number of attachments per private message.
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import static org.briarproject.briar.api.attachment.MediaConstants.MAX_CONTENT_T
|
|||||||
import static org.briarproject.briar.api.attachment.MediaConstants.MSG_KEY_CONTENT_TYPE;
|
import static org.briarproject.briar.api.attachment.MediaConstants.MSG_KEY_CONTENT_TYPE;
|
||||||
import static org.briarproject.briar.api.attachment.MediaConstants.MSG_KEY_DESCRIPTOR_LENGTH;
|
import static org.briarproject.briar.api.attachment.MediaConstants.MSG_KEY_DESCRIPTOR_LENGTH;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_INCOMING_TEXT_LENGTH;
|
||||||
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
||||||
import static org.briarproject.briar.messaging.MessageTypes.ATTACHMENT;
|
import static org.briarproject.briar.messaging.MessageTypes.ATTACHMENT;
|
||||||
import static org.briarproject.briar.messaging.MessageTypes.PRIVATE_MESSAGE;
|
import static org.briarproject.briar.messaging.MessageTypes.PRIVATE_MESSAGE;
|
||||||
@@ -103,7 +103,7 @@ class PrivateMessageValidator implements MessageValidator {
|
|||||||
// Private message text
|
// Private message text
|
||||||
checkSize(body, 1);
|
checkSize(body, 1);
|
||||||
String text = body.getString(0);
|
String text = body.getString(0);
|
||||||
checkLength(text, 0, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
|
checkLength(text, 0, MAX_PRIVATE_MESSAGE_INCOMING_TEXT_LENGTH);
|
||||||
// Return the metadata
|
// Return the metadata
|
||||||
BdfDictionary meta = new BdfDictionary();
|
BdfDictionary meta = new BdfDictionary();
|
||||||
meta.put(MSG_KEY_TIMESTAMP, m.getTimestamp());
|
meta.put(MSG_KEY_TIMESTAMP, m.getTimestamp());
|
||||||
@@ -117,7 +117,7 @@ class PrivateMessageValidator implements MessageValidator {
|
|||||||
// Message type, optional private message text, attachment headers
|
// Message type, optional private message text, attachment headers
|
||||||
checkSize(body, 3);
|
checkSize(body, 3);
|
||||||
String text = body.getOptionalString(1);
|
String text = body.getOptionalString(1);
|
||||||
checkLength(text, 0, MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
|
checkLength(text, 0, MAX_PRIVATE_MESSAGE_INCOMING_TEXT_LENGTH);
|
||||||
BdfList headers = body.getList(2);
|
BdfList headers = body.getList(2);
|
||||||
if (text == null) checkSize(headers, 1, MAX_ATTACHMENTS_PER_MESSAGE);
|
if (text == null) checkSize(headers, 1, MAX_ATTACHMENTS_PER_MESSAGE);
|
||||||
else checkSize(headers, 0, MAX_ATTACHMENTS_PER_MESSAGE);
|
else checkSize(headers, 0, MAX_ATTACHMENTS_PER_MESSAGE);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import static org.briarproject.briar.api.attachment.MediaConstants.MAX_CONTENT_T
|
|||||||
import static org.briarproject.briar.api.attachment.MediaConstants.MSG_KEY_CONTENT_TYPE;
|
import static org.briarproject.briar.api.attachment.MediaConstants.MSG_KEY_CONTENT_TYPE;
|
||||||
import static org.briarproject.briar.api.attachment.MediaConstants.MSG_KEY_DESCRIPTOR_LENGTH;
|
import static org.briarproject.briar.api.attachment.MediaConstants.MSG_KEY_DESCRIPTOR_LENGTH;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_INCOMING_TEXT_LENGTH;
|
||||||
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
||||||
import static org.briarproject.briar.messaging.MessageTypes.ATTACHMENT;
|
import static org.briarproject.briar.messaging.MessageTypes.ATTACHMENT;
|
||||||
import static org.briarproject.briar.messaging.MessageTypes.PRIVATE_MESSAGE;
|
import static org.briarproject.briar.messaging.MessageTypes.PRIVATE_MESSAGE;
|
||||||
@@ -55,7 +55,7 @@ public class PrivateMessageValidatorTest extends BrambleMockTestCase {
|
|||||||
private final Message message = getMessage(group.getId());
|
private final Message message = getMessage(group.getId());
|
||||||
private final long now = message.getTimestamp() + 1000;
|
private final long now = message.getTimestamp() + 1000;
|
||||||
private final String text =
|
private final String text =
|
||||||
getRandomString(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
|
getRandomString(MAX_PRIVATE_MESSAGE_INCOMING_TEXT_LENGTH);
|
||||||
private final BdfList attachmentHeader = getAttachmentHeader();
|
private final BdfList attachmentHeader = getAttachmentHeader();
|
||||||
private final MessageId attachmentId = new MessageId(getRandomId());
|
private final MessageId attachmentId = new MessageId(getRandomId());
|
||||||
private final String contentType = getRandomString(MAX_CONTENT_TYPE_BYTES);
|
private final String contentType = getRandomString(MAX_CONTENT_TYPE_BYTES);
|
||||||
@@ -132,7 +132,7 @@ public class PrivateMessageValidatorTest extends BrambleMockTestCase {
|
|||||||
@Test(expected = InvalidMessageException.class)
|
@Test(expected = InvalidMessageException.class)
|
||||||
public void testRejectsTooLongTextForLegacyMessage() throws Exception {
|
public void testRejectsTooLongTextForLegacyMessage() throws Exception {
|
||||||
String invalidText =
|
String invalidText =
|
||||||
getRandomString(MAX_PRIVATE_MESSAGE_TEXT_LENGTH + 1);
|
getRandomString(MAX_PRIVATE_MESSAGE_INCOMING_TEXT_LENGTH + 1);
|
||||||
|
|
||||||
testRejectsLegacyMessage(BdfList.of(invalidText));
|
testRejectsLegacyMessage(BdfList.of(invalidText));
|
||||||
}
|
}
|
||||||
@@ -190,7 +190,7 @@ public class PrivateMessageValidatorTest extends BrambleMockTestCase {
|
|||||||
@Test(expected = InvalidMessageException.class)
|
@Test(expected = InvalidMessageException.class)
|
||||||
public void testRejectsTooLongTextForPrivateMessage() throws Exception {
|
public void testRejectsTooLongTextForPrivateMessage() throws Exception {
|
||||||
String invalidText =
|
String invalidText =
|
||||||
getRandomString(MAX_PRIVATE_MESSAGE_TEXT_LENGTH + 1);
|
getRandomString(MAX_PRIVATE_MESSAGE_INCOMING_TEXT_LENGTH + 1);
|
||||||
|
|
||||||
testRejectsPrivateMessage(
|
testRejectsPrivateMessage(
|
||||||
BdfList.of(PRIVATE_MESSAGE, invalidText, new BdfList()));
|
BdfList.of(PRIVATE_MESSAGE, invalidText, new BdfList()));
|
||||||
|
|||||||
Reference in New Issue
Block a user