cucumber/common

cucumber-expressions: combinatorial explosion of generated expressions

Closed this issue · 1 comments

Summary

Using only small input values it is possible make CucumberExpressionGenerator generate 1.5GB worth of generated expressions.

For example: the step a simple step -a total of 11 letters- and 4 parameters with a the regular expression of [a-z] we will generate a whopping 4^11=419430 possible cucumber expressions. As each GeneratedExpression takes up approximately 11*32 bytes this totals just shy of 1.5GB.

Possible Solution

While this can be avoided by not using parameter types with overly generic expressions for snippet generation, snippet generation is enabled by default and once we run out memory it is impossible to inform or warn anyone about this problem.

new ParameterType<>(
        "myType",
        "[a-z]",
        String.class,
        new Transformer<String>() {
            @Override
            public String transform(String arg) {
                return arg;
            }
        },
        false, // useForSnippet
        false  // preferForRegexpMatch
);

So 256 cucumber expressions should be enough for anyone.

Steps to Reproduce (for bugs)

@Test
public void test_to_destruction() {
    ParameterTypeRegistry parameterTypeRegistry = new ParameterTypeRegistry(Locale.ENGLISH);
    CucumberExpressionGenerator generator = new CucumberExpressionGenerator(parameterTypeRegistry);
    
    for (int i = 0; i < 4; i++) {
        ParameterType<String> genericOne = new ParameterType<>(
                "myType"+i,
                "[a-z]",
                String.class,
                new Transformer<String>() {
                    @Override
                    public String transform(String arg) {
                        return arg;
                    }
                },
                true,
                false
        );
        parameterTypeRegistry.defineParameterType(genericOne);

    }

    List<GeneratedExpression> generatedExpressions = generator.generateExpressions("a simple step");
    assertEquals(4194304, generatedExpressions.size());
}

Context & Motivation

cucumber/cucumber-jvm#1579

lock commented

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.