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

tokio::io::Take overflows on 32bit target #6070

Closed
svenrademakers opened this issue Oct 12, 2023 · 3 comments · Fixed by #6080
Closed

tokio::io::Take overflows on 32bit target #6070

svenrademakers opened this issue Oct 12, 2023 · 3 comments · Fixed by #6080
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-io Module: tokio/io

Comments

@svenrademakers
Copy link

Version

cargo tree | grep tokio
│   │   │   ├── tokio v1.32.0
│   │   │   │   └── tokio-macros v2.1.0 (proc-macro)
│   │   │   ├── tokio-util v0.7.9
│   │   │   │   ├── tokio v1.32.0 (*)
│   │   │   └── tokio v1.32.0 (*)
│   │   │   ├── tokio v1.32.0 (*)
│   │   │   ├── tokio-openssl v0.6.3
│   │   │   │   └── tokio v1.32.0 (*)
│   │   │   ├── tokio-util v0.7.9 (*)
│   │   │   ├── tokio v1.32.0 (*)
│   │   │   ├── tokio-util v0.7.9 (*)
│   │   ├── tokio v1.32.0 (*)
│   │   ├── tokio-util v0.7.9 (*)
│   │   │   ├── tokio v1.32.0 (*)
│   └── tokio v1.32.0 (*)
├── tokio v1.32.0 (*)
├── tokio-serial v5.4.4
│   ├── tokio v1.32.0 (*)
│   └── tokio-util v0.7.9 (*)
├── tokio-stream v0.1.14
│   └── tokio v1.32.0 (*)
└── tokio-util v0.7.9 (*)

Platform

  • host = x86_64 GNU/Linux
  • target = QEMU?! armel, armv7-unknown-linux-gnueabi
    (tested on real armv7 target as well)

Description

calling tokio::io::copy on my armv7 target returned exactly with u32::MAX bytes left to copy. I distilled the problem into a generic tokio test, but the behavior is still not as expected.

given the following test-case:

    use tokio::io::{sink, AsyncReadExt};

    #[tokio::test]
    async fn big_copy_test() -> std::io::Result<()> {
        // make sure it overflows usize on 32bit targets
        let mut reader = tokio::io::repeat(0b101).take(u32::MAX as u64 + 1u64);
        let copied = tokio::io::copy(&mut reader, &mut sink()).await?;
        assert_eq!(copied, u32::MAX as u64 + 1u64);
        Ok(())
    }

Completes successfully, as expected, on x64 executed via:
cargo test big_copy_test

FAILS on armv7-linux-gnueabi using cross-rs:
cross test big_copy --target armv7-unknown-linux-gnueabi --release

Outcome:

running 1 test
test utils::io::test::big_copy_test ... thread 'utils::io::test::big_copy_test' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `4294967296`', src/utils/io.rs:88:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
FAILED

Expected:
left == right, test passed.

@svenrademakers svenrademakers added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Oct 12, 2023
@Darksonn Darksonn added the M-io Module: tokio/io label Oct 13, 2023
@Darksonn
Copy link
Contributor

Thanks for reporting this. I've filed a PR with a fix.

@Darksonn Darksonn changed the title tokio::io::copy overflows on 32bit target tokio::io::Take overflows on 32bit target Oct 15, 2023
@Darksonn
Copy link
Contributor

I've renamed the issue since the problem is actually in take, as far as I can tell.

@svenrademakers
Copy link
Author

No thank you for looking into this! Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-io Module: tokio/io
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants