Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix random "UTF8 string too large" exception in ScalaSigAnnotationVisitor #24

Merged
merged 1 commit into from
Feb 10, 2022

Conversation

vladimirkl
Copy link
Contributor

This PR fixes random "UTF8 string too large" exception during shading, which I encountered in my closed source project. This exception is very hard to reproduce because it occurs during processing classes that have ScalaLongSignature annotation and annotation value should have zero bytes in certain places, which is not deterministic. The cause of this bug is nextChunk function in ScalaSigAnnotationVisitor class which can produce chunks equal to 65536 bytes breaking org.objectweb.asm.ByteVector#putUTF8. Stack trace for exception is following:

java.lang.IllegalArgumentException: UTF8 string too large
     at org.objectweb.asm.ByteVector.encodeUtf8(ByteVector.java:298)
     at org.objectweb.asm.ByteVector.putUTF8(ByteVector.java:265)
     at org.objectweb.asm.SymbolTable.addConstantUtf8(SymbolTable.java:774)
     at org.objectweb.asm.AnnotationWriter.visit(AnnotationWriter.java:198)
     at com.eed3si9n.jarjarabrams.scalasig.ScalaSigAnnotationVisitor.rewriteAnnotation(ScalaSigAnnotationVisitor.scala:91)
     at com.eed3si9n.jarjarabrams.scalasig.ScalaSigAnnotationVisitor.visitEnd(ScalaSigAnnotationVisitor.scala:47)
     at org.objectweb.asm.ClassReader.readElementValues(ClassReader.java:3003)
     at org.objectweb.asm.ClassReader.readElementValue(ClassReader.java:3173)
     at org.objectweb.asm.ClassReader.readElementValues(ClassReader.java:2993)
     at org.objectweb.asm.ClassReader.accept(ClassReader.java:608)
     at org.objectweb.asm.ClassReader.accept(ClassReader.java:424)
     at com.eed3si9n.jarjar.ScalaSigProcessor.process(ScalaSigProcessor.scala:15)
     at com.eed3si9n.jarjar.util.JarProcessorChain.process(JarProcessorChain.java:38)
     at com.eed3si9n.jarjar.JJProcessor.process(JJProcessor.scala:108)
     at com.eed3si9n.jarjarabrams.Shader$.$anonfun$bytecodeShader$6(Shader.scala:75)
     at com.eed3si9n.jarjarabrams.Shader$.$anonfun$shadeDirectory$4(Shader.scala:21

This PR extracts nextChunk to standalone function, fixes the bug and adds a test for it. Unfortunately cannot include actual class causing error because it is from closed source project and there is no deterministic way to recreate it.

@eed3si9n eed3si9n merged commit 84e1a2c into eed3si9n:develop Feb 10, 2022
@vladimirkl
Copy link
Contributor Author

@eed3si9n Thank you for merging this. Is it possible to make a patch release for this library and sbt-assembly in near future?

@eed3si9n eed3si9n mentioned this pull request Feb 11, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants