mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 11:46:53 +00:00
Avoid overflows when calculating media ciphertext size
This commit is contained in:
1 parent
68b3e9a07c
commit
56f25f5a39
4 files changed
+55
-10
No files matched your search
+1
-1
@@ -485,7 +485,7 @@ public class BackupManagerTest {
|
||||
|
||||
// Copying can start on the next batch of USAGE_CHECKPOINT_COUNT before the current one is done, so we should see
|
||||
// at least one usage update, and at most 2
|
||||
final long bytesPerObject = COPY_ENCRYPTION_PARAM.outputSize(100);
|
||||
final long bytesPerObject = CopyParameters.destinationObjectSize(100);
|
||||
assertThat(backupsDb.getMediaUsage(backupUser).join().usageInfo()).isIn(
|
||||
new UsageInfo(
|
||||
bytesPerObject * backupConfiguration.usageCheckpointCount(),
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2026 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.backup;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
class CopyParametersTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"0, 64",
|
||||
"15, 64",
|
||||
"16, 80",
|
||||
"2_147_483_647, 2_147_483_696"
|
||||
})
|
||||
void destinationObjectSize(final int inputSize, final long expectedOutputSize) {
|
||||
assertEquals(expectedOutputSize, CopyParameters.destinationObjectSize(inputSize));
|
||||
}
|
||||
|
||||
@Test
|
||||
void destinationObjectSizeNegative() {
|
||||
assertThrows(IllegalArgumentException.class, () -> CopyParameters.destinationObjectSize(-1));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user