Skip to content

Fix mutate 13 error for input sizes longer than 127 bytes

Marcos Rocha requested to merge mc_rocha-fix-large-input-sizes-error-6 into master

As described on issue #6 (closed), the mutate 13(Replace an ascii digit with another digit) didn't work for input longer than 127 bytes.

The issue was happening because of the integer to byte conversion here:

for (int k=0; k<res.length; k++) {
   if (res[k] >= 48 && res[k] <= 57) {
       digits.add((byte)k);
   }
}

Convert an integer longer than 127 to byte could result in a negative value.

int integerValue = 128;
byte byteValue = (byte)integerValue;
System.out.println(byteValue);

-128

Process finished with exit code 0

The negative value was being used as index of the res array, causing the index out of bonds exception.

int pos = this.rand(digits.size());
int was = res[digits.get(pos)];

This Merge request fix this issue.

How to run the tests

To run the unit test added on this MR is necessary to update the Corpus.java file. The line 160 should be updated from

int x = this.rand(16);

to

int x = 13;

This change is necessary to force the method mutate to use the variant 13.

Screenshots

Running the tests with old version

Screen_Shot_2021-11-17_at_10.09.09_AM

Running the tests with the new version

Screen_Shot_2021-11-17_at_10.11.09_AM

Edited by Marcos Rocha

Merge request reports

Loading