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

error "TConnectedClient processing exception: Expected control char, got '/'" when a string argument contains a slash and JSON is used

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 0.10.0, 0.11.0, 0.12.0, 0.13.0
    • None
    • None
    • Linux 4.15.0-74-generic #83~16.04.1-Ubuntu SMP Wed Dec 18 04:56:23 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

    Description

      When calling a method from php THttpClient / TJSONProtocol client to a C ++ server, an error occurs if the argument of the function contains a "/" slash.

      php client displays an error::

      PHP Fatal error:  Uncaught Thrift\Exception\TTransportException: THttpClient: Could not connect to localhost:9090 in /usr/lib/php/Thrift/Transport/THttpClient.php:27
      

      C++ server displays an error::

      Thrift: Thu Feb 13 10:22:23 2020 TConnectedClient processing exception: Expected control char, got '/'.
      

      If the request from JS (TXHRTransport / TJSONProtocol) to the C ++ server, everything is fine

      If the request from php (THttpClient / TJSONProtocol) to python THttpServer / TJSONProtocol everything is fine

       

      sample.thrift:

      service Bug {
         void bug(1:string val),
      }
      

       

      thrift -r --gen php sample.thrift
      thrift -r --gen cpp sample.thrift
      

       

      client on php

      <?php
      $GLOBALS['THRIFT_ROOT'] = '/usr/lib/php';
      
      require_once $GLOBALS['THRIFT_ROOT'].'/Thrift/ClassLoader/ThriftClassLoader.php';
      
      use Thrift\ClassLoader\ThriftClassLoader;
      
      $GEN_DIR = 'gen-php';
      
      $loader = new ThriftClassLoader();
      $loader->registerNamespace( 'Thrift', $GLOBALS['THRIFT_ROOT'] );
      $loader->register();
      
      use Thrift\Protocol\TJSONProtocol;
      use Thrift\Transport\THttpClient;
      use Thrift\Transport\TBufferedTransport;
      
      require_once $GEN_DIR.'/Bug.php';
      require_once $GEN_DIR.'/Types.php';
      
      $socket = new THttpClient( '127.0.0.1', 9090 );
      $transport = new TBufferedTransport( $socket, 1024, 1024 );
      $protocol = new TJSONProtocol( $transport );
      $client = new BugClient( $protocol );
      
      $client->bug( 'str' ); // ok
      $client->bug( 'str with / slash' ); // PHP Fatal error
      
      // PHP Fatal error:  Uncaught Thrift\Exception\TTransportException: THttpClient: Could not connect to localhost:9090 in /usr/lib/php/Thrift/Transport/THttpClient.php:27
      

       

      server on c++

      #include "gen-cpp/Bug.h"
      
      #include  <iostream>
      
      #include <thrift/protocol/TJSONProtocol.h>
      #include <thrift/server/TThreadedServer.h>
      #include <thrift/transport/THttpServer.h>
      #include <thrift/transport/TServerSocket.h>
      
      using namespace ::apache::thrift;
      using namespace ::apache::thrift::protocol;
      using namespace ::apache::thrift::transport;
      using namespace ::apache::thrift::server;
      using namespace ::apache::thrift::async;
      
      using boost::shared_ptr;
      
      class BugHandler : virtual public BugIf {
      
          void bug(const std::string& val) {
                std::cout << val << std::endl;
          }
      };
      
      int main(int argc, char ** argv) {
      
          shared_ptr<BugHandler>          bug( new BugHandler() );
          shared_ptr<TProcessor>          processor( new BugProcessor(bug) );
          shared_ptr<TTransportFactory>   transportFactory( new THttpServerTransportFactory() );
          shared_ptr<TProtocolFactory>    protocolFactory( new TJSONProtocolFactory() );
          shared_ptr<TServerTransport>    serverTransport( new TServerSocket( 9090 ) );
      
          shared_ptr<TThreadedServer>     server( new TThreadedServer( processor, serverTransport, transportFactory, protocolFactory ) );
      
          server->serve();
      
          return 0;
      }
      

      Attachments

        1. php_unescaped_slashes.path
          0.4 kB
          Thrift Bugger

        Activity

          People

            Unassigned Unassigned
            ThriftBugger Thrift Bugger
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: