-
Notifications
You must be signed in to change notification settings - Fork 956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning false if file does not end with .class #580
Returning false if file does not end with .class #580
Conversation
When using scriptOutputDir as a param to -javaagent, the folder might contain non Java class files. Ensuring that the files loaded into BTrace is a .class file.
@@ -750,6 +750,10 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) | |||
} | |||
|
|||
private static boolean loadBTraceScript(String filePath, boolean traceToStdOut) { | |||
if (!filePath.endsWith(".class")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you modify this to look at the magic bytes instead?
For Java class files it would be 0xCAFEBABE
and for the BTrace probe-pack it is 0xBACECACA
.
The problem with only extension check is that the BTrace probe-pack can have any extension name - it is not really standardized. For simplicity it defaults to .class
but it is possible to specify some other extension so you eg. don't confuse the classloader if the BTrace probe pack files are put together with regular class files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would I check for the magic bytes? Is it as simple as opening the file, read the first few bytes and compare them to the mentioned 2 magic bytes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I am sorry, I completely missed the notification about the activity here :(
Yes, it is exactly the way you are describing. It is 4 first bytes of the file which is containing the magic number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for contributing!
Please, see my comments 'inline'
Hi @joachimhs , same as for #579 - will you be able to finish this PR, please? |
Ok, I am going to merge as it is and add the magic number checks as a followup step. |
When using scriptOutputDir as a param to -javaagent, the folder might contain non Java class files. Ensuring that the files loaded into BTrace is a .class file.