On Friday 01 February 2008 18:51, Robert Hailey wrote:
> 
> On Feb 1, 2008, at 12:33 PM, Alberto Bacchelli wrote:
> 
> > 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
> 
> I'm not really sure this is so much a bug as garbage-in-garbage-out.
> 
> By the code provided, the size for the bitarray is given first, then  
> the raw data; it just so happens that when you translate the first  
> several bytes of "testString" into an integer, it comes out to be very  
> large number (more bytes than are available for allocation). Note that  
> there *is* a legitimate bitarray data stream which will begin with  
> "testString".asBytes(), it is probably just too large for practical use.

Do we use this anywhere, that is the question?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20080201/338424eb/attachment.pgp>

Reply via email to