Skip to content

clipboard kitten can hang depending on the size of the data coming from stdin #8059

@alex-huff

Description

@alex-huff

Description
If the number of bytes being copied from stdin to kitten clipboard is:
(8192 * n + 1) for all n where n >= 0 and n % 3 != 1 or
(8192 * n + 2) for all n where n >= 0 and n % 3 == 0,
then the clipboard kitten will hang indefinitely.

Reproducing

kitten clipboard <<< "" # \n

or

kitten clipboard <<< "a" # a\n

or

python -c "print('a' * 16385, end='')" | kitten clipboard

...and so on

For all the values of n described above, the final read from data_src in write_one_chunk returns less than 3 bytes. Those bytes are then written to the base64 encoder enc. However, this small write doesn't trigger a write to the underlying base64_streaming_enc. This means data is never submitted to the loop and so OnWriteComplete is never called. Since data_src only gets read again as a result of OnWriteComplete, and because data_src has a Read implementation that doesn't return EOF until an attempt to read past n, the kitten hangs indefinitely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions