From d75d372da0e672fa1ceb6bd76b9ccd866356bc9d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 20 Aug 2024 17:37:25 +0530 Subject: [PATCH] Reset base64 streaming decoder after invalid input Fixes #7757 --- docs/changelog.rst | 2 ++ kitty/clipboard.py | 7 ++++++- kitty/notifications.py | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9192d9d92..4e3aaaeb3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -83,6 +83,8 @@ Detailed list of changes - Remote control: Fix a regression causing an escape code to leak when using @ launch with ``--no-response`` over the TTY (:iss:`7752`) +- OSC 52: Fix a regression in the previous release that broke handling of invalid base64 encoded data in OSC 52 requests (:iss:`7757`) + 0.36.0 [2024-08-17] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/clipboard.py b/kitty/clipboard.py index 2800f368f..b0ac1f292 100644 --- a/kitty/clipboard.py +++ b/kitty/clipboard.py @@ -289,7 +289,12 @@ def flush_base64_data(self) -> None: def write_base64_data(self, b: bytes) -> None: if not self.max_size_exceeded: - decoded = self.decoder.decode(b) + try: + decoded = self.decoder.decode(b) + except ValueError: + log_error('Clipboard write request has invalid data, ignoring this chunk of data') + self.decoder.reset() + decoded = b'' if decoded: self.tempfile.write(decoded) if self.max_size > 0 and self.tempfile.tell() > (self.max_size * 1024 * 1024): diff --git a/kitty/notifications.py b/kitty/notifications.py index dd3503ab4..c05ac0fe7 100644 --- a/kitty/notifications.py +++ b/kitty/notifications.py @@ -189,7 +189,12 @@ def add_unencoded_data(self, data: Union[str, bytes]) -> None: def add_base64_data(self, data: Union[str, bytes]) -> None: if isinstance(data, str): data = data.encode('ascii') - self.data_store(self.decoder.decode(data)) + try: + decoded = self.decoder.decode(data) + except ValueError: + log_error('Ignoring invalid base64 encoded data in notification request') + else: + self.data_store(decoded) def flush_encoded_data(self) -> None: self.decoder.reset()