Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackOverflowException when obfuscating pattern matching switch #444

Open
boq opened this issue Oct 28, 2024 · 1 comment
Open

StackOverflowException when obfuscating pattern matching switch #444

boq opened this issue Oct 28, 2024 · 1 comment

Comments

@boq
Copy link

boq commented Oct 28, 2024

Replicated in Proguard 7.6.0 and JDK 21.0.2.

Reproduction case:

public class SwitchTest {
    public interface Type {
    }

    public enum Types implements Type {A}

    public static String test(final Type type) {
        return switch (type) {
            case Types.A -> "a";
            default -> "?";
        };
    }
}

Repeated stacktrace section looks like this:

	at proguard.classfile.ProgramClass.attributesAccept(ProgramClass.java:613)
	at proguard.classfile.editor.ConstantPoolShrinker.visitDynamicConstant(ConstantPoolShrinker.java:142)
	at proguard.classfile.constant.DynamicConstant.accept(DynamicConstant.java:109)
	at proguard.classfile.ProgramClass.constantPoolEntryAccept(ProgramClass.java:555)
	at proguard.classfile.attribute.BootstrapMethodInfo.methodArgumentsAccept(BootstrapMethodInfo.java:57)
	at proguard.classfile.editor.ConstantPoolShrinker.visitBootstrapMethodInfo(ConstantPoolShrinker.java:403)
	at proguard.classfile.attribute.BootstrapMethodsAttribute.bootstrapMethodEntriesAccept(BootstrapMethodsAttribute.java:58)
	at proguard.classfile.editor.ConstantPoolShrinker.visitBootstrapMethodsAttribute(ConstantPoolShrinker.java:209)
	at proguard.classfile.attribute.BootstrapMethodsAttribute.accept(BootstrapMethodsAttribute.java:49)
	at proguard.classfile.ProgramClass.attributesAccept(ProgramClass.java:613)

It seems to be triggered by Dynamic entry (and probably InvokeDynamic) in any of the arguments in BootstrapMethods attribute. Code in visitDynamicConstant seems to pass visitor back to class, which visits all attributes, eventually running back into BootstrapMethods and repeating whole process.

@rgaschy
Copy link

rgaschy commented Jan 8, 2025

I've encountered the exact same issue.
It can still be reproduced on proguard 7.6.1 and JDK 21.0.2.
Here attached is a simple project that allows to reproduce the issue:

  • unzip it
  • run gradlew obfuscate --stacktrace
    (Basically, it wraps the class above in a gradle project)

proguard.zip

Would you please have a look at this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants