Skip to content

Commit d6fcfe1

Browse files
committed
prevented zero length modifications
1 parent 02cc135 commit d6fcfe1

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ public class ByteArrayModificationFactory {
4949
public static final String FILE_NAME = "de/rub/nds/modifiablevariable/explicit/array.vec";
5050

5151
/**
52-
*
53-
* @param xor
54-
* bytes to xor
55-
* @param startPosition
56-
* negative numbers mean that the position is taken from the end
52+
*
53+
* @param xor bytes to xor
54+
* @param startPosition negative numbers mean that the position is taken
55+
* from the end
5756
* @return variable modification
5857
*/
5958
public static VariableModification<byte[]> xor(final byte[] xor, final int startPosition) {
@@ -62,8 +61,7 @@ public static VariableModification<byte[]> xor(final byte[] xor, final int start
6261

6362
/**
6463
*
65-
* @param payload
66-
* bytes are set as value
64+
* @param payload bytes are set as value
6765
* @return variable modification
6866
*/
6967
public static VariableModification<byte[]> payload(final byte[] payload) {
@@ -72,11 +70,10 @@ public static VariableModification<byte[]> payload(final byte[] payload) {
7270

7371
/**
7472
* *
75-
*
76-
* @param bytesToInsert
77-
* bytes to xor
78-
* @param startPosition
79-
* negative numbers mean that the position is taken from the end
73+
*
74+
* @param bytesToInsert bytes to xor
75+
* @param startPosition negative numbers mean that the position is taken
76+
* from the end
8077
* @return variable modification
8178
*/
8279
public static VariableModification<byte[]> insert(final byte[] bytesToInsert, final int startPosition) {
@@ -85,11 +82,10 @@ public static VariableModification<byte[]> insert(final byte[] bytesToInsert, fi
8582

8683
/**
8784
* * Deletes $count bytes from the input array beginning at $startPosition
88-
*
89-
* @param startPosition
90-
* negative numbers mean that the position is taken from the end
91-
* @param count
92-
* number of bytes to be deleted
85+
*
86+
* @param startPosition negative numbers mean that the position is taken
87+
* from the end
88+
* @param count number of bytes to be deleted
9389
* @return variable modification
9490
*/
9591
public static VariableModification<byte[]> delete(final int startPosition, final int count) {
@@ -98,7 +94,7 @@ public static VariableModification<byte[]> delete(final int startPosition, final
9894

9995
/**
10096
* Duplicates the byte array
101-
*
97+
*
10298
* @return duplicate variable modification
10399
*/
104100
public static VariableModification<byte[]> duplicate() {
@@ -117,9 +113,8 @@ public static VariableModification<byte[]> explicitValueFromFile(int value) {
117113

118114
/**
119115
* Shuffles the bytes in the array, given a specified array of positions.
120-
*
121-
* @param shuffle
122-
* positions that define shuffling
116+
*
117+
* @param shuffle positions that define shuffling
123118
* @return shuffling variable modification
124119
*/
125120
public static VariableModification<byte[]> shuffle(final byte[] shuffle) {
@@ -162,13 +157,19 @@ public static VariableModification<byte[]> createRandomModification(byte[] origi
162157
switch (r) {
163158
case BYTE_ARRAY_XOR_MODIFICATION:
164159
int modificationArrayLength = random.nextInt(modifiedArrayLength);
160+
if (modificationArrayLength == 0) {
161+
modificationArrayLength++;
162+
}
165163
byte[] xor = new byte[modificationArrayLength];
166164
random.nextBytes(xor);
167165
int startPosition = random.nextInt(modifiedArrayLength - modificationArrayLength);
168166
vm = new ByteArrayXorModification(xor, startPosition);
169167
return vm;
170168
case BYTE_ARRAY_INSERT_MODIFICATION:
171169
modificationArrayLength = random.nextInt(MAX_CONFIG_PARAMETER);
170+
if (modificationArrayLength == 0) {
171+
modificationArrayLength++;
172+
}
172173
byte[] bytesToInsert = new byte[modificationArrayLength];
173174
random.nextBytes(bytesToInsert);
174175
int insertPosition = random.nextInt(modifiedArrayLength);
@@ -182,6 +183,9 @@ public static VariableModification<byte[]> createRandomModification(byte[] origi
182183
return vm;
183184
case BYTE_ARRAY_EXPLICIT_VALUE_MODIFICATION:
184185
modificationArrayLength = random.nextInt(MAX_CONFIG_PARAMETER);
186+
if (modificationArrayLength == 0) {
187+
modificationArrayLength++;
188+
}
185189
byte[] explicitValue = new byte[modificationArrayLength];
186190
random.nextBytes(explicitValue);
187191
vm = new ByteArrayExplicitValueModification(explicitValue);

0 commit comments

Comments
 (0)