Skip to content

Commit

Permalink
jackson-dataformats-binary: Add loops to parser method calling (#11363)
Browse files Browse the repository at this point in the history
This PR adds looping for calling methods of different parsers in the
jackson-dataformats-binary project to simulate multiple method calling
for the same initialized parser.

---------

Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan authored Dec 14, 2023
1 parent c882997 commit f55f09e
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 295 deletions.
120 changes: 61 additions & 59 deletions projects/jackson-dataformats-binary/AvroParserFuzzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class AvroParserFuzzer {
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
try {
Integer choice = data.consumeInt(1, 19);
int[] choices = data.consumeInts(data.consumeInt(1, 100));

// Retrieve set of AvroMapper.Feature
EnumSet<AvroParser.Feature> featureSet = EnumSet.allOf(AvroParser.Feature.class);
Expand Down Expand Up @@ -54,64 +54,66 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) {
((AvroMapper) mapper).getFactory().createParser(data.consumeRemainingAsBytes());

// Fuzz methods of AvroParser
switch (choice) {
case 1:
parser.currentName();
break;
case 2:
parser.currentTokenLocation();
break;
case 3:
parser.currentLocation();
break;
case 4:
parser.isExpectedStartArrayToken();
break;
case 5:
parser.isExpectedNumberIntToken();
break;
case 6:
parser.nextToken();
break;
case 7:
parser.nextTextValue();
break;
case 8:
parser.getText();
break;
case 9:
parser.getTextCharacters();
break;
case 10:
parser.getTextLength();
break;
case 11:
parser.getTextOffset();
break;
case 12:
parser.getNumberType();
break;
case 13:
parser.getNumberValue();
break;
case 14:
parser.getIntValue();
break;
case 15:
parser.getLongValue();
break;
case 16:
parser.getBigIntegerValue();
break;
case 17:
parser.getFloatValue();
break;
case 18:
parser.getDoubleValue();
break;
case 19:
parser.getDecimalValue();
break;
for (Integer choice : choices) {
switch (choice % 19) {
case 1:
parser.currentName();
break;
case 2:
parser.currentTokenLocation();
break;
case 3:
parser.currentLocation();
break;
case 4:
parser.isExpectedStartArrayToken();
break;
case 5:
parser.isExpectedNumberIntToken();
break;
case 6:
parser.nextToken();
break;
case 7:
parser.nextTextValue();
break;
case 8:
parser.getText();
break;
case 9:
parser.getTextCharacters();
break;
case 10:
parser.getTextLength();
break;
case 11:
parser.getTextOffset();
break;
case 12:
parser.getNumberType();
break;
case 13:
parser.getNumberValue();
break;
case 14:
parser.getIntValue();
break;
case 15:
parser.getLongValue();
break;
case 16:
parser.getBigIntegerValue();
break;
case 17:
parser.getFloatValue();
break;
case 18:
parser.getDoubleValue();
break;
default:
parser.getDecimalValue();
break;
}
}

parser.close();
Expand Down
120 changes: 61 additions & 59 deletions projects/jackson-dataformats-binary/CborParserFuzzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class CborParserFuzzer {
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
try {
Integer choice = data.consumeInt(1, 19);
int[] choices = data.consumeInts(data.consumeInt(1, 100));

// Retrieve set of CBORParser.Feature
EnumSet<CBORParser.Feature> featureSet = EnumSet.allOf(CBORParser.Feature.class);
Expand All @@ -47,64 +47,66 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) {
((CBORMapper) mapper).getFactory().createParser(data.consumeRemainingAsBytes());

// Fuzz methods of CBORParser
switch (choice) {
case 1:
parser.currentName();
break;
case 2:
parser.currentTokenLocation();
break;
case 3:
parser.currentLocation();
break;
case 4:
parser.isExpectedStartArrayToken();
break;
case 5:
parser.isExpectedNumberIntToken();
break;
case 6:
parser.nextToken();
break;
case 7:
parser.nextTextValue();
break;
case 8:
parser.getText();
break;
case 9:
parser.getTextCharacters();
break;
case 10:
parser.getTextLength();
break;
case 11:
parser.getTextOffset();
break;
case 12:
parser.getNumberType();
break;
case 13:
parser.getNumberValue();
break;
case 14:
parser.getIntValue();
break;
case 15:
parser.getLongValue();
break;
case 16:
parser.getBigIntegerValue();
break;
case 17:
parser.getFloatValue();
break;
case 18:
parser.getDoubleValue();
break;
case 19:
parser.getDecimalValue();
break;
for (Integer choice : choices) {
switch (choice % 19) {
case 1:
parser.currentName();
break;
case 2:
parser.currentTokenLocation();
break;
case 3:
parser.currentLocation();
break;
case 4:
parser.isExpectedStartArrayToken();
break;
case 5:
parser.isExpectedNumberIntToken();
break;
case 6:
parser.nextToken();
break;
case 7:
parser.nextTextValue();
break;
case 8:
parser.getText();
break;
case 9:
parser.getTextCharacters();
break;
case 10:
parser.getTextLength();
break;
case 11:
parser.getTextOffset();
break;
case 12:
parser.getNumberType();
break;
case 13:
parser.getNumberValue();
break;
case 14:
parser.getIntValue();
break;
case 15:
parser.getLongValue();
break;
case 16:
parser.getBigIntegerValue();
break;
case 17:
parser.getFloatValue();
break;
case 18:
parser.getDoubleValue();
break;
default:
parser.getDecimalValue();
break;
}
}

parser.close();
Expand Down
Loading

0 comments on commit f55f09e

Please sign in to comment.