Skip to content
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

improve error message when verifying magic bytes of the input #337

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions core/src/main/java/org/jboss/jandex/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2085,9 +2085,15 @@ private boolean isJDK11OrNewer(DataInputStream stream) throws IOException {
}

private void verifyMagic(DataInputStream stream) throws IOException {
final int magic = stream.readInt();
final int magic;
try {
magic = stream.readInt();
} catch (EOFException e) {
throw new EOFException("Input is not a valid class file; must begin with a 4-byte integer 0xCAFEBABE");
}
if (magic != 0xCA_FE_BA_BE) {
throw new IOException("Invalid Magic");
throw new IOException("Input is not a valid class file; must begin with a 4-byte integer 0xCAFEBABE, "
+ "but seen 0x" + Integer.toHexString(magic).toUpperCase());
}
}

Expand Down
Loading