problem with cdollins/grizzly-google-protobufs

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with cdollins/grizzly-google-protobufs

dragonken
This post has NOT been accepted by the mailing list yet.
Hi All,

I tried the unit test from grizzly-google-protobufs (ProtobufFilterTest). I found something weird in ProtobufDecoder class.

The incoming message (input) has position 4 (which is the header length) and thus the first read for message header return an incorrect value (168195689).

Log:
11:16:52.996 [Grizzly-worker(2)] DEBUG ProtobufDecoder - StringDecoder decode protobufSize=null buffer=HeapBuffer (1877713025) [pos=0 lim=14 cap=14] content= vipaca

11:16:52.998 [Grizzly-worker(2)] DEBUG ProtobufDecoder - protobufSize=10
11:16:53.053 [Grizzly-worker(2)] DEBUG ProtobufFilterTest - Got the protobuf: name: "vipaca"
age: 28

11:16:53.055 [Grizzly-worker(2)] DEBUG ProtobufDecoder - StringDecoder decode protobufSize=null buffer=HeapBuffer (1877713025) [pos=4 lim=14 cap=14] content= vipaca

11:16:53.056 [Grizzly-worker(2)] DEBUG ProtobufDecoder - protobufSize=168195689
11:16:53.056 [Grizzly-worker(1)] DEBUG ProtobufDecoder - StringDecoder decode protobufSize=null buffer=HeapBuffer (1915231999) [pos=0 lim=14 cap=14] content= vipaca
11:16:53.056 [Grizzly-worker(1)] DEBUG ProtobufDecoder - protobufSize=10
11:16:53.056 [Grizzly-worker(1)] DEBUG ProtobufDecoder - StringDecoder decode protobufSize=null buffer=HeapBuffer (1915231999) [pos=4 lim=14 cap=14] content= vipaca
11:16:53.056 [Grizzly-worker(1)] DEBUG ProtobufDecoder - protobufSize=168195689
11:16:53.056 [Grizzly-worker(2)] DEBUG ProtobufDecoder - input.remaining() < protobufSize!
11:16:53.056 [Grizzly-worker(1)] DEBUG ProtobufDecoder - input.remaining() < protobufSize!


ProtobufDecoder.transformImpl(). I use Log4j2.

    @Override
    protected TransformationResult<Buffer, Message> transformImpl(final AttributeStorage storage, final Buffer input)
            throws TransformationException {
        Integer protobufSize = lengthAttribute.get(storage);
 
        logger.debug("StringDecoder decode protobufSize={} buffer={} content={}",
                    protobufSize, input, input.toStringContent());


        if (protobufSize == null) {
            if (input.remaining() < LENGTH_HEADER_SIZE) {
                return TransformationResult.createIncompletedResult(input);
            }

            protobufSize = input.getInt();
            lengthAttribute.set(storage, protobufSize);
        }

        logger.debug("protobufSize={}", protobufSize);
       
        if (input.remaining() < protobufSize) {
            logger.debug("input.remaining() < protobufSize!");
            return TransformationResult.createIncompletedResult(input);
        }
       
        final int pos = input.position();
        final BufferInputStream stream = new BufferInputStream(input, pos, pos + protobufSize);
        final Message protobufMessage;
        try {
            protobufMessage = message.newBuilderForType().mergeFrom(stream).build();
        } catch (InvalidProtocolBufferException e) {
            final String msg = "InvalidProtocolBufferException during ProtocolBuffer construction.";
            logger.error(msg);
            return TransformationResult.createErrorResult(INVALID_PROTOCOL_BUFFER_ERROR, msg);
        } catch (IOException e) {
            final String msg = "IOException during ProtocolBuffer construction.";
            logger.error(msg);
            return TransformationResult.createErrorResult(IO_EXCEPTION_DURING_PROTOBUF_CREATION_ERROR, msg);
        }

        return TransformationResult.createCompletedResult(protobufMessage, input);
    }

Please kindly help.

Regards,
Ken
Reply | Threaded
Open this post in threaded view
|

Re: problem with cdollins/grizzly-google-protobufs

dragonken
This post has NOT been accepted by the mailing list yet.
Hi,

I added one line in decoder and seems solved the problem.

        final int pos = input.position();
        final BufferInputStream stream = new BufferInputStream(input, pos, pos + protobufSize);
        input.position(pos+protobufSize);
        final Message protobufMessage;
        try {
            protobufMessage = message.newBuilderForType().mergeFrom(stream).build();
        } catch (InvalidProtocolBufferException e) {
            final String msg = "InvalidProtocolBufferException during ProtocolBuffer construction.";
            logger.error(msg);
            return TransformationResult.createErrorResult(INVALID_PROTOCOL_BUFFER_ERROR, msg);
        } catch (IOException e) {
            final String msg = "IOException during ProtocolBuffer construction.";
            logger.error(msg);
            return TransformationResult.createErrorResult(IO_EXCEPTION_DURING_PROTOBUF_CREATION_ERROR, msg);
        }
Reply | Threaded
Open this post in threaded view
|

Re: problem with cdollins/grizzly-google-protobufs

dragonken
This post has NOT been accepted by the mailing list yet.
Hi,

Please advise my fix is correct or not.

Regards,
Ken