kovidgoyal/kitty · warning

Clipboard write request payload is not valid base64, abortin

Error message

Clipboard write request payload is not valid base64, aborting the write request. Error: {e}

What it means

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.

Source

Thrown at kitty/clipboard.py:465

                self.abort_write_request(wr, 'EINVAL')
                return
            for alias in aliases:
                wr.aliases[alias] = mime
        elif typ == 'wdata':
            wr = self.in_flight_write_request
            if wr is None:
                return
            mime = m.get('mime', '')
            try:
                if not mime:
                    self.commit_write_request(wr)
                    return
                wr.add_base64_data(epayload, mime)
            except OSError:
                self.abort_write_request(wr, 'EIO')
                raise
            except ValueError as e:
                log_error(f'Clipboard write request payload is not valid base64, aborting the write request. Error: {e}')
                self.abort_write_request(wr, 'EINVAL')
                return
            except Exception:
                self.abort_write_request(wr, 'EINVAL')
                raise
            if wr.max_size_exceeded:
                self.abort_write_request(wr, 'EFBIG')

    def abort_write_request(self, wr: WriteRequest, status: str) -> None:
        self.in_flight_write_request = None
        w = get_boss().window_id_map.get(self.window_id)
        if w is not None:
            w.screen.send_escape_code_to_child(ESC_OSC, wr.encode_response(status=status))

    def commit_write_request(self, wr: WriteRequest, needs_flush: bool = True) -> None:
        if needs_flush:
            wr.flush_base64_data()
        wr.commit()

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Chunk wdata payloads at multiples of 4 base64 characters
  2. Send the final chunk only when the remaining length is a multiple of 4 (with padding)
  3. Validate your encoder output before writing to the pty

Example fix

# before
for i in range(0, len(b64), 1000): send_chunk(b64[i:i+1000])
# after
for i in range(0, len(b64), 4*1000): send_chunk(b64[i:i+4000])
Defensive patterns

Strategy: validation

Validate before calling

def chunks_ok(b64: str, n: int) -> bool:
    return n % 4 == 0 and len(b64) % 4 == 0 or n >= len(b64)

Prevention

When it happens

Trigger: Sending a wdata chunk whose bytes are not valid streaming base64 (length not multiple of 4 mid-stream, illegal characters).

Common situations: Clients splitting base64 at arbitrary byte boundaries instead of multiples of 4; buffering code that drops characters.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/16614fea273b9a92. Report an issue: GitHub.