{"record":{"id":"16614fea273b9a92","repo":"kovidgoyal/kitty","slug":"clipboard-write-request-payload-is-not-valid-base6","errorCode":null,"errorMessage":"Clipboard write request payload is not valid base64, aborting the write request. Error: {e}","messagePattern":"Clipboard write request payload is not valid base64, aborting the write request\\. Error: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kitty/clipboard.py","lineNumber":465,"sourceCode":"                self.abort_write_request(wr, 'EINVAL')\n                return\n            for alias in aliases:\n                wr.aliases[alias] = mime\n        elif typ == 'wdata':\n            wr = self.in_flight_write_request\n            if wr is None:\n                return\n            mime = m.get('mime', '')\n            try:\n                if not mime:\n                    self.commit_write_request(wr)\n                    return\n                wr.add_base64_data(epayload, mime)\n            except OSError:\n                self.abort_write_request(wr, 'EIO')\n                raise\n            except ValueError as e:\n                log_error(f'Clipboard write request payload is not valid base64, aborting the write request. Error: {e}')\n                self.abort_write_request(wr, 'EINVAL')\n                return\n            except Exception:\n                self.abort_write_request(wr, 'EINVAL')\n                raise\n            if wr.max_size_exceeded:\n                self.abort_write_request(wr, 'EFBIG')\n\n    def abort_write_request(self, wr: WriteRequest, status: str) -> None:\n        self.in_flight_write_request = None\n        w = get_boss().window_id_map.get(self.window_id)\n        if w is not None:\n            w.screen.send_escape_code_to_child(ESC_OSC, wr.encode_response(status=status))\n\n    def commit_write_request(self, wr: WriteRequest, needs_flush: bool = True) -> None:\n        if needs_flush:\n            wr.flush_base64_data()\n        wr.commit()","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/clipboard.py#L447-L483","documentation":"A wdata chunk of an OSC 5522 write request raised ValueError (invalid base64 via the streaming decoder); the write request is aborted with EINVAL and parsing of that chunk stops.","triggerScenarios":"Sending a wdata chunk whose bytes are not valid streaming base64 (length not multiple of 4 mid-stream, illegal characters).","commonSituations":"Clients splitting base64 at arbitrary byte boundaries instead of multiples of 4; buffering code that drops characters.","solutions":["Chunk wdata payloads at multiples of 4 base64 characters","Send the final chunk only when the remaining length is a multiple of 4 (with padding)","Validate your encoder output before writing to the pty"],"exampleFix":"# before\nfor i in range(0, len(b64), 1000): send_chunk(b64[i:i+1000])\n# after\nfor i in range(0, len(b64), 4*1000): send_chunk(b64[i:i+4000])","handlingStrategy":"validation","validationCode":"def chunks_ok(b64: str, n: int) -> bool:\n    return n % 4 == 0 and len(b64) % 4 == 0 or n >= len(b64)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chunk base64 at multiples of 4 characters","Only the final chunk may carry padding"],"tags":["kitty","clipboard","osc5522","base64","chunking"],"backgroundTag":"base64-decode-invalid-input","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}