Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1240

TBinarySerializer.php invalid serialization due to TBufferTransport not flushing last chunk of data into TMemoryBuffer

    XMLWordPrintableJSON

Details

    • Patch Available

    Description

      Simple Serialization errors out, due to the TBufferTransport not flushing the data into TMemoryBuffer after $object->write($protocol) in TBinarySerializer.
      Please find the error output of my test program below. It fixed after I added the following line on the serialize method in TBinarySerializer.

      $protocol->getTransport()->flush();

      This because of TBinaryProtocolAccelerated internally wraps TMemoryBuffer within TBufferTransport in its constructor.

      TBufferTransport write only if the wbuf_ is full (512 bytes) into TMemoryBuffer. Hence data smaller than 512 will not get written into TMemoryBuffer. While getting serialized data from TMemoryBuffer it might not have the last chunk of data which is less than 512 bytes.

      This outputs invalid serialized data

      TestSchema$ php testsimple.php

      Serialized .
      mari
      Fatal error: Uncaught exception 'TTransportException' with message 'TMemoryBuffer: Could not read 512 bytes from buffer.' in /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/transport/TMemoryBuffer.php on line 58

      TTransportException: TMemoryBuffer: Could not read 512 bytes from buffer. in /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/transport/TMemoryBuffer.php on line 58

      Call Stack:
      0.0003 636976 1.

      {main}() /Users/mponnambalam/work/eclipse/workspace/TestSchema/testsimple.php:0
      0.0043 1509728 2. TBinarySerializer::deserialize() /Users/mponnambalam/work/eclipse/workspace/TestSchema/testsimple.php:47
      0.0043 1511808 3. thrift_protocol_read_binary() /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/protocol/TBinarySerializer.php:62



      thrift_protoco_read_binary disabled ( I commented extension in thrift_protocol.ini)

      TestSchema$ php testsimple.php

      Serialized .
      Fatal error: Uncaught exception 'TTransportException' with message 'TMemoryBuffer: Could not read 1 bytes from buffer.' in /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/transport/TMemoryBuffer.php on line 58

      TTransportException: TMemoryBuffer: Could not read 1 bytes from buffer. in /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/transport/TMemoryBuffer.php on line 58

      Call Stack:
      0.0003 636976 1. {main}

      () /Users/mponnambalam/work/eclipse/workspace/TestSchema/testsimple.php:0
      0.0041 1509944 2. TBinarySerializer::deserialize() /Users/mponnambalam/work/eclipse/workspace/TestSchema/testsimple.php:47
      0.0041 1512248 3. Person->read() /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/protocol/TBinarySerializer.php:66
      0.0041 1512472 4. TBinaryProtocol->readFieldBegin() /Users/mponnambalam/work/eclipse/workspace/TestSchema/gen-php/simple/simple_types.php:45
      0.0041 1512472 5. TBinaryProtocol->readByte() /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/protocol/TBinaryProtocol.php:231
      0.0041 1512520 6. TBufferedTransport->readAll() /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/protocol/TBinaryProtocol.php:283
      0.0041 1512568 7. TTransport->readAll() /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/transport/TBufferedTransport.php:109
      0.0041 1512744 8. TMemoryBuffer->read() /Users/mponnambalam/work/eclipse/workspace/thrift0.6.1/lib/php/src/transport/TTransport.php:87

      Attachments

        1. simple.thrift
          0.1 kB
          Marimuthu Ponnambalam
        2. testsimple.php
          0.6 kB
          Marimuthu Ponnambalam
        3. TBinarySerializer.php
          3 kB
          Marimuthu Ponnambalam

        Activity

          People

            marimuthupg Marimuthu Ponnambalam
            marimuthupg Marimuthu Ponnambalam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: