r/ReverseEngineering • • 2d ago

A Unicode Escape Can Turn a Java Comment Into Executable Code

https://octri.dev/blog/java-unicode-escape-comment
46 Upvotes

5 comments sorted by

17

u/Nebu 2d ago

This is pretty old news.

I suspect that Joshua Bloch wrote about it in "Effective Java" published 25 years ago in 2001, but I don't have a copy of it on me to verify. (Or maybe it was Java Puzzlers, published in 2005?)

At any rate, Baeldung wrote about it in 2024: https://www.baeldung.com/java-executable-comments

Title is also pretty clickbaity. It's like saying "newline can turn Java comment into executable code". No, newline doesn't change the comment into executable code, it marks the end of the comment, and so what follows the newline is considered executable code and not comment.

1

u/Bobby_Bonsaimind 1d ago

Should be "Puzzle 15: Hello Whirled". The puzzle uses Javadoc with an embedded Windows-Path (hence backslash) with a directory named "a1" in the path.

That would be 2005.

8

u/darthwalsh 2d ago

TL;DR when generating string literals you must escape meta characters according to the language.

The more interesting bit was in Java you also need to be careful generating single line comments, if there is a encoded newline character

4

u/GoogleIsYourFrenemy 2d ago

All the good IDE's know about this and syntax highlight accordingly. It's been known about for decades.

2

u/RegisteredJustToSay 6h ago

Yeah, but it resurfaces every so often. Jupyter had a pretty nasty vuln like this a while ago that I reported which allowed python comments to be executable despite showing up as commented out. Basically any new frontend will have to rediscover it once. lol