xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #2072: clipboard.patch

File clipboard.patch, 4.0 KB (added by Calvin Ko, 3 years ago)
  • xpra/clipboard/clipboard_base.py

     
    107107        self.can_send = d.boolget("can-send", True)
    108108        self.can_receive = d.boolget("can-receive", True)
    109109        self.max_clipboard_packet_size = MAX_CLIPBOARD_PACKET_SIZE
     110        self.max_clipboard_receive_size = MAX_CLIPBOARD_PACKET_SIZE
     111        self.max_clipboard_send_size = MAX_CLIPBOARD_PACKET_SIZE
    110112        self.disabled_by_loop = []
    111113        self.filter_res = []
    112114        filter_res = d.strlistget("filters")
     
    131133
    132134    def get_info(self):
    133135        info = {
    134                 "type"      : str(self).replace("ClipboardProtocolHelper", ""),
    135                 "max_size"  : self.max_clipboard_packet_size,
     136                "type"      :       str(self).replace("ClipboardProtocolHelper", ""),
     137                "max_size"  :       self.max_clipboard_packet_size,
     138                "max_recv_size":    self.max_clipboard_receive_size,
     139                "max_send_size":    self.max_clipboard_send_size,
    136140                "filters"   : [x.pattern for x in self.filter_res],
    137141                "requests"  : self._clipboard_request_counter,
    138142                "pending"   : tuple(self._clipboard_outstanding_requests.keys()),
     
    199203                        if selection not in self.disabled_by_loop:
    200204                            self.disabled_by_loop.append(selection)
    201205
    202     def set_direction(self, can_send, can_receive):
     206    def set_direction(self, can_send, can_receive, max_send_size=-1, max_receive_size=-1):
    203207        self.can_send = can_send
    204208        self.can_receive = can_receive
     209        if max_send_size >= 0:
     210            self.max_clipboard_send_size = max_send_size
     211        if max_receive_size >= 0:
     212            self.max_clipboard_receive_size = max_receive_size
    205213        for proxy in self._clipboard_proxies.values():
    206214            proxy.set_direction(can_send, can_receive)
    207215
     
    435443
    436444    def _munge_wire_selection_to_raw(self, encoding, dtype, dformat, data):
    437445        log("wire selection to raw, encoding=%s, type=%s, format=%s, len(data)=%s", encoding, dtype, dformat, len(data or ""))
     446        if dformat > 8:
     447            max_recv_datalen = self.max_clipboard_receive_size * 8 / dformat
     448        else:
     449            max_recv_datalen = self.max_clipboard_receive_size
     450        if len(data) > max_recv_datalen:
     451            olen = len(data)
     452            data = data[:max_recv_datalen]
     453            log.info("Data copied out truncated because of clipboard policy %d to %d", olen, max_recv_datalen)
    438454        if encoding == b"bytes":
    439455            return data
    440456        elif encoding == b"integers":
     
    490506            if dtype is None or data is None or (dformat==0 and data==b""):
    491507                no_contents()
    492508                return
     509            log("perform security checking - datasize - %d, %d", len(data), self.max_clipboard_send_size)
     510            if dformat > 8:
     511                max_send_datalen = self.max_clipboard_send_size * 8 / dformat
     512            else:
     513                max_send_datalen = self.max_clipboard_send_size
     514            if len(data) > max_send_datalen:
     515                truncated = len(data) - max_send_datalen
     516                data = data[:max_send_datalen]
     517            else:
     518                truncated = 0
    493519            munged = self._munge_raw_selection_to_wire(target, dtype, dformat, data)
    494520            wire_encoding, wire_data = munged
    495521            log("clipboard raw -> wire: %r -> %r", (dtype, dformat, data), munged)
     
    499525            wire_data = self._may_compress(dtype, dformat, wire_data)
    500526            if wire_data is not None:
    501527                self.send("clipboard-contents", request_id, selection,
    502                        dtype, dformat, wire_encoding, wire_data)
     528                       dtype, dformat, wire_encoding, wire_data, truncated)
    503529        proxy.get_contents(target, got_contents)
    504530
    505531    def _may_compress(self, dtype, dformat, wire_data):