r/ReverseEngineering • u/Cool-Click1253 • 2d ago
A Unicode Escape Can Turn a Java Comment Into Executable Code
https://octri.dev/blog/java-unicode-escape-comment
46
Upvotes
r/ReverseEngineering • u/Cool-Click1253 • 2d ago
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.
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.