tomp2p / TomP2P

A P2P-based high performance key-value pair storage library
http://tomp2p.net
Apache License 2.0
438 stars 122 forks source link

DataSerializer bug? #105

Closed Menooker closed 9 years ago

Menooker commented 9 years ago

net/tomp2p/storage/DataSerializer.java

private Data deserializeMapDB(DataInput in) throws IOException {
    ByteBuf buf = Unpooled.buffer();
    Data data = null;
    while(data == null) {
        buf.writeByte(in.readByte());
        data = Data.decodeHeader(buf, signatureFactory);
    }
    int len = data.length();
    byte me[] = new byte[len];
    in.readFully(me);
    buf = Unpooled.wrappedBuffer(me);
    boolean retVal = data.decodeBuffer(buf);
    if(!retVal) {
        throw new IOException("data could not be read");
    }
    retVal = data.decodeDone(buf, signatureFactory);
    if(!retVal) {
        throw new IOException("signature could not be read");
    }
    return data;
}

This function always throws IOException("signature could not be read") I think this line goes wrong : retVal = data.decodeDone(buf, signatureFactory); Because "buf" is still the buffer for "data.decodeBuffer"!!! Maybe you should read the buffer before "data.decodeDone"? : )

tbocek commented 9 years ago

You are right! There was a bug in the decoder and I forgot to read the buffer before decodeDone(). Thanks for this bugreport!

ChronosXYZ commented 5 years ago

Oh, where you was earlier?!?!