0

AsyncProcess::read_stdout() fails decoding when receiving split UTF-8 sequences

Mathias Anderssén 6 years ago 0

I discovered an issue with AsyncProcess::read_stdout() and read_stderr() in exec.py: If for some reason os.read() returns a split UTF-8 sequence the decoding will fail.


I found this by having a custom build system running g++ on a remote machine over Putty's plink.exe


Not being proficient in Python the fix I use is to simply buffer up the returned data:


    def read_stdout(self):

        buf = bytes()

        while True:

            data = os.read(self.proc.stdout.fileno(), 2**15)

            if len(data) > 0:

                buf += data

            else:

                if len(buf) > 0 and self.listener:

                    self.listener.on_data(self, buf)

                self.proc.stdout.close()

                if self.listener:

                    self.listener.on_finished(self)

                break