Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- fix: add stricter validation for Ed25519 Signed Payload.
- fix: replace assert statements with explicit null checks in `Federation` class to ensure validation is not bypassed when assertions are disabled.
- fix: add overflow check in `TimeBounds.expiresAfter()` to prevent integer overflow when timeout is too large.
- fix: add validation for `ManageDataOperation` value length to ensure it does not exceed 64 bytes.

## 2.2.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public ManageDataOperation build() {
if (new XdrString(op.name).getBytes().length > 64) {
throw new IllegalArgumentException("name cannot exceed 64 bytes");
}
if (op.value != null && op.value.length > 64) {
throw new IllegalArgumentException("value cannot exceed 64 bytes");
}
return op;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;

import org.junit.Test;
import org.stellar.sdk.KeyPair;
Expand Down Expand Up @@ -57,4 +58,40 @@ public void testManageDataOperationEmptyValue() {
"AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAA=",
operation.toXdrBase64());
}

@Test
public void testManageDataOperationValueExceeds64Bytes() {
byte[] value = new byte[65];
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class,
() -> ManageDataOperation.builder().name("test").value(value).build());
assertEquals("value cannot exceed 64 bytes", exception.getMessage());
}

@Test
public void testManageDataOperationValueExactly64Bytes() {
byte[] value = new byte[64];
for (int i = 0; i < 64; i++) {
value[i] = (byte) i;
}
ManageDataOperation operation = ManageDataOperation.builder().name("test").value(value).build();
assertArrayEquals(value, operation.getValue());
}

@Test
public void testManageDataOperationNameExceeds64Bytes() {
String name = "12345678901234567890123456789012345678901234567890123456789012345";
IllegalArgumentException exception =
assertThrows(
IllegalArgumentException.class, () -> ManageDataOperation.builder().name(name).build());
assertEquals("name cannot exceed 64 bytes", exception.getMessage());
}

@Test
public void testManageDataOperationNameExactly64Bytes() {
String name = "1234567890123456789012345678901234567890123456789012345678901234";
ManageDataOperation operation = ManageDataOperation.builder().name(name).build();
assertEquals(name, operation.getName());
}
}
Loading