Profiles gRPC: update SetProfileRequest.data max length

This commit is contained in:
Chris Eager authored and Jon Chambers committed 2026-10-21 16:15:06 -04:00
1 parent 1c4933e23c
commit 3f79eb32c3
3 files changed
+29 -28

No files matched your search

@@ -120,8 +120,10 @@ message SetProfileRequest {
bytes version = 1 [(require.exactlySize) = 32];
// The ciphertext of a serialized Profile protobuf. Required.
// 937 max length = 909 plaintext serialization + 28 bytes encryption overhead
bytes data = 2 [(require.nonEmpty) = true, (require.size).max = 937];
// 1486 max length = 1202 plaintext serialization
// + 256-byte external padding PKCS#7
// + 28 bytes encryption overhead
bytes data = 2 [(require.nonEmpty) = true, (require.size).max = 1486];
// The SHA-256 hash of the Profile ciphertext being replaced.
// This is used an optimistic lock against concurrent changes.
@@ -98,6 +98,7 @@ import org.whispersystems.textsecuregcm.entities.BadgeSvg;
import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
import org.whispersystems.textsecuregcm.limits.RateLimiter;
import org.whispersystems.textsecuregcm.limits.RateLimiters;
import org.whispersystems.textsecuregcm.purchases.ReceiptLevel;
import org.whispersystems.textsecuregcm.s3.PostPolicyGenerator;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.AccountBadge;
@@ -108,7 +109,6 @@ import org.whispersystems.textsecuregcm.storage.ProfilesManager;
import org.whispersystems.textsecuregcm.storage.VersionedProfile;
import org.whispersystems.textsecuregcm.storage.VersionedProfileV1;
import org.whispersystems.textsecuregcm.storage.WriteConflictException;
import org.whispersystems.textsecuregcm.purchases.ReceiptLevel;
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
import org.whispersystems.textsecuregcm.tests.util.ProfileTestHelper;
import org.whispersystems.textsecuregcm.util.MockUtils;
@@ -973,35 +973,33 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
assertTrue(statusRuntimeException.getStatus().getDescription().toLowerCase(Locale.ROOT).contains("commitment"));
}
@ParameterizedTest
@ValueSource(ints = {0, 1, 16, 32})
void testProfileSerialized(int aboutEmojiLength) {
@Test
void testProfileSerialized() {
// This test demonstrates the calculation for the (require.size).max = 909 + 28
// in profiles.proto, as well as how padding calculation results in a constant size.
//
// This test demonstrates the calculation for the (require.size).max = 1202 + 256 + 28
// in profiles.proto
// This should be largely integrated into libsignal in the future.
// in gRPC, field + varint length encoding has:
// field number: 1 byte per field < number 16
// varint: 1 byte for length < 128, 2 bytes for < 16,384
final int serializedSize =
1 + 257 + 2 +
1 + 257 + 2 +
1 + 512 + 2 +
1 + aboutEmojiLength + 1 +
1 + 64 + 1 +
1 + 1 +
1 + (64 - (257 + 512 + aboutEmojiLength + 64 + 1) % 64) + 1;
1 + 32 + 1 +
1 + 128 + 2 +
1 + 1;
assertEquals(909, serializedSize);
assertEquals(1202, serializedSize);
final PlaintextProfileData data = PlaintextProfileData.newBuilder()
.setNameBytes(ByteString.copyFrom(new byte[257]))
.setGivenNameBytes(ByteString.copyFrom(new byte[257]))
.setFamilyNameBytes(ByteString.copyFrom(new byte[257]))
.setAboutBytes(ByteString.copyFrom(new byte[512]))
.setAboutEmojiBytes(ByteString.copyFrom(new byte[aboutEmojiLength]))
.setAvatarBytes(ByteString.copyFrom(new byte[64]))
.setAboutEmojiBytes(ByteString.copyFrom(new byte[32]))
.setAvatarBytes(ByteString.copyFrom(new byte[128]))
.setPhoneNumberSharing(true)
.setPadding(ByteString.copyFrom(new byte[64 - (257 + 512 + aboutEmojiLength + 64 + 1) % 64]))
.build();
assertEquals(serializedSize, data.getSerializedSize());
+11 -10
View File
@@ -5,15 +5,16 @@ option java_multiple_files = true;
package org.signal.chat.profile.test;
// This may be removed in favor of a canonical libsignal definition in a future release
// Externally padded using PKCS#7
message PlaintextProfileData {
string name = 1; // max length = 257
optional string about = 2; // max length = 512
optional string aboutEmoji = 3; // max length = 32
optional string avatar = 4; // max length = 64
bool phoneNumberSharing = 5;
// 15 is the highest field number without serialization overhead
optional bytes padding = 15; // length = 64 - (len(name) + len(about) + len(aboutEmoji) + len(avatar) + 1) % 64
// next: 6
string givenName = 1; // min length = 1, max length = 257
string familyName = 2; // min length = 0, max length = 257
string about = 3; // min length = 0, max length = 512
string aboutEmoji = 4; // min length = 0, max length = 32
// URL of the user's avatar. The domain must be one of Signal's known CDN domains.
// If the user has no avatar, this will be empty.
string avatar = 5; // min length = 0, max length = 128
bool phoneNumberSharing = 6;
// next: 7
}