Skip to content

Commit 5b4f07a

Browse files
committed
Fixed a possible division by zero exception in the bytearray shuffle modification
1 parent f80a129 commit 5b4f07a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*/
2323
@XmlRootElement
24-
@XmlType(propOrder = { "shuffle", "modificationFilter", "postModification" })
24+
@XmlType(propOrder = {"shuffle", "modificationFilter", "postModification"})
2525
public class ByteArrayShuffleModification extends VariableModification<byte[]> {
2626

2727
private byte[] shuffle;
@@ -41,12 +41,14 @@ protected byte[] modifyImplementationHook(final byte[] input) {
4141
}
4242
byte[] result = input.clone();
4343
int size = input.length;
44-
for (int i = 0; i < shuffle.length - 1; i += 2) {
45-
int p1 = (shuffle[i] & 0xff) % size;
46-
int p2 = (shuffle[i + 1] & 0xff) % size;
47-
byte tmp = result[p1];
48-
result[p1] = result[p2];
49-
result[p2] = tmp;
44+
if (size != 0) {
45+
for (int i = 0; i < shuffle.length - 1; i += 2) {
46+
int p1 = (shuffle[i] & 0xff) % size;
47+
int p2 = (shuffle[i + 1] & 0xff) % size;
48+
byte tmp = result[p1];
49+
result[p1] = result[p2];
50+
result[p2] = tmp;
51+
}
5052
}
5153
return result;
5254
}

0 commit comments

Comments
 (0)