Hi,

 trying some automatic test case generator on the code, I found that
there is a bug in freenet.support.BitArray.
It is not a problem in the Freenet code, but it seems a Java problem
(maybe only with the VM version I am using which is Java(TM) SE Runtime
Environment (build 1.6.0_03-b05) ).

if you run this test:

public void testConstructorThrowsEOFException1() throws Throwable {
        DataInputStream dis = new DataInputStream(new
ByteArrayInputStream("testString".getBytes()));
        try {
            new BitArray(dis);
            fail("Expected EOFException to be thrown");
        } catch (EOFException ex) {
            assertEquals("ex.getClass()", EOFException.class,
ex.getClass());
            assertThrownBy(DataInputStream.class, ex);
            assertEquals("dis.available()", 0, dis.available());
        }
}

you will probably get a java.lang.OutOfMemoryError.

This is caused by a bad value returned by readInt() in the following code:


    public BitArray(DataInputStream dis) throws IOException {
        _size = dis.readInt();
        _bits = new byte[(_size / 8) + (_size % 8 == 0 ? 0 : 1)];
        dis.readFully(_bits);
    }  

the simpliest way to solve this issue imho is to find a way to avoid
using readInt().

Sback

Reply via email to