Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bytes are being dropped by cat command -- likely an issue with applications/app_io or libs/stdio #473

vikrammullick opened this issue Dec 14, 2021 · 1 comment


Copy link

The 256th (indexed at 0) byte is being dropped when writing to stdout (and possibly when reading from stdin though this hasn't been tested).

To reproduce, run cat on a text file that is longer than 256 bytes to observe that every 256th byte is dropped.

It seems likely that this is an off-by-one error either in applications/app_io or libs/stdio.

Copy link

Ok, finally found the culprit! (Took me a while since i wasn't the original author of that stdio code)

The code responsible for this is in the try_read() function here:

while let (Some(buf_elem), Some(queue_elem)) = (, locked_ring_buf.queue.pop_front()) {

Basically, it unconditionally pops the front item off of the stdio buffer, even when there is no next item in the buffer.

The fix is to only call pop_front() iff there is another element in the destination buf.

I am fixing this for now since it's an obvious bug. Also, note that a full stdio redesign is in the works too, which will be more akin to an arbitrary byte stream, so this code will eventually be removed anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants