[java] escape backslashes in escapeForJavadoc to stop comment breakout - #3903
Open
arib06 wants to merge 1 commit into
Open
[java] escape backslashes in escapeForJavadoc to stop comment breakout#3903arib06 wants to merge 1 commit into
arib06 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
SpecificCompiler.escapeForJavadocembeds untrusted schemadocstrings into generated Javadoc comments and neutralizes only a literal*/,<and>. javac decodes Unicode escapes before it strips comments (JLS 3.3), so adocvalue carrying the backslash-u escapes for the comment terminator is emitted verbatim and decoded to*/in the generated source, ending the Javadoc early and turning the rest of the doc into code. A field-level doc lands right before the field declaration, so the injected text becomes a clean class member.The sibling
escapeForJavaString(used for theSCHEMA$literal) already doubles backslashes, so that path is safe; the Javadoc path was the gap. This applies the same neutralization at the single escaping helper, before the existing*/replacement, so no eligible Unicode escape can form. Valid docs without backslashes are emitted unchanged.Verifying this change
This change added tests and can be verified as follows:
TestSpecificCompiler#docCannotBreakOutViaUnicodeEscape, which compiles a record whose field doc contains a backslash-u escape for the comment terminator and asserts no eligible Unicode escape survives in any generated file. It fails on the pre-fix code and passes after.docsAreEscaped_avro4053and the tools golden-file codegen tests still pass (docs without backslashes are unaffected).Documentation