ClassReader constructor goes into infinite loop on zero length input streams
Following code leads into an infinite loop with ClassReader constructor when args[0] is an empty file:
public class Asm61InfiniteLoop
{
public static void main(String[] args) throws java.io.IOException
{
java.io.FileInputStream input = new java.io.FileInputStream(args[0]);
new org.objectweb.asm.ClassReader(input);
}
}
It looks like the following snippet in the constructor is the culprit where data leads into a zero length array with zero length files and the bytes read from the actual stream never get to -1:
byte[] data = new byte[inputStream.available()];
int bytesRead;
while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) {
outputStream.write(data, 0, bytesRead);
}
I would expect this to throw an exception about invalid class data or similar. Other constructors relying on byte[] data being at least 6 elements long lead into out of bounds exception. That is a little bit better, but still weird from user's perspective.