Closed samczsun closed 6 years ago
Actually, looks like a lot of attributes fall into this category. For example, according to the hotspot source RuntimeInvisibleAnnotations
isn't parsed for anything older than 49, so .attribute RuntimeInvisibleAnnotations '\x00\x00\x00\x00'
will cause a crash in Krakatau but no error in the JVM. I assume that Class#getAnnotations
will be affected for 49+ but I haven't tested it
I'd been meaning to look into what happens when you use predefined attributes with a version before they were defined, but never got around to it and then forgot. Thanks for catching this.
I did some testing to try to figure out which versions each attribute is verified in, but I ran into some issues - it looks like some attributes aren't verified at all, regardless of the version. There's also the question of how to handle e.g. stack maps in version 50.0, where they are optional, as well as attributes defined in the wrong place.
I can't even use the brute force approach of wrapping attribute assembly in a try block and emitting binary if it fails because the disassembler is single pass so attribute assembly may have already written partial output by the time it throws.
Sounds like a fun problem.
Because of the single pass issue, I guess you could write separate verifiers for each attribute type to make sure that the binary data conforms to the spec. Then if the blob passes verification you could pass it onto the current disassembling code.
I think it would be easier to just change the disassembler to output to a temporary buffer when disassembling attributes.
I decided to go with the approach of trying to disassemble the attributes and falling back to binary output if there is an error. It took some horrible hacks to properly support the case of version 50 StackMapTable attributes, but at least it works. Anyway, please try it out and see what you think.
Awesome! Bit busy this week but I can't wait to give it a shot
Not really sure what happened here on Krakatau's end, but the JVM doesn't parse
StackMapTable
attributes for version < 50 so I assume you can stick any arbitrary data in there and Krakatau won't handle it too well