From 618acc6ea2e46cbc95647df9800514e55d2f4401 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Wed, 18 Oct 2023 17:58:22 +0200 Subject: [PATCH] improve error message when verifying magic bytes of the input --- core/src/main/java/org/jboss/jandex/Indexer.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/jboss/jandex/Indexer.java b/core/src/main/java/org/jboss/jandex/Indexer.java index 47e66a03..29df11eb 100644 --- a/core/src/main/java/org/jboss/jandex/Indexer.java +++ b/core/src/main/java/org/jboss/jandex/Indexer.java @@ -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()); } }