rust-lang / rust-lang/rust

Issue with `write_all_at` on GitHub Action

Open
#140,867 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug C-external-bug O-linux T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

write_all_at doesn't write the buffer at the given index. The content is written at the end of the file.
I created a repo on my github https://github.com/allevo/rust-fs-write-all-bug to show the error.

Locally on Mac M2, the test on that repo passes, but on CI it doesn't.

NB:

  • write_all_at and read_exact_at doesn't change the cursor position
  • flush or/and sync_all doesn't fix

I tried this code:

use std::{io::Write, os::unix::fs::FileExt, path::PathBuf};

pub fn run(file_path: PathBuf) {
    let mut page_file = std::fs::File::options()
        .create(true)
        .append(true)
        .read(true)
        .open(&file_path)
        .unwrap();

    let n: u32 = 10;
    let buf: [u8; 4] = n.to_be_bytes();
    page_file
        .write_all_at(&buf, 0).unwrap();

    page_file.flush().unwrap();
    page_file
        .sync_all().unwrap();

    let mut buf: [u8; 4] = [0; 4];
    page_file
        .read_exact_at(&mut buf, 0).unwrap();
    let n = u32::from_be_bytes(buf);

    page_file.seek(SeekFrom::Start(0)).unwrap();

    let buf: [u8; 4] = (n + 1).to_be_bytes();
    page_file
        .write_all_at(&buf, 0).unwrap();
}

I expected to see this happen: The file content will be [0, 0, 0, 11]

Instead, this happened: [0, 0, 0, 10, 0, 0, 0, 11]

Meta

rustup --version && rustc --version --verbose:

info: This is the version for the rustup toolchain manager, not the rustc compiler.
rustup 1.2[8](https://github.com/allevo/rust-fs-write-all-bug/actions/runs/14934973609/job/41960164587#step:3:9).1 (f9edccde0 2025-03-05)
info: The currently active `rustc` version is `rustc 1.86.0 (05f[9](https://github.com/allevo/rust-fs-write-all-bug/actions/runs/14934973609/job/41960164587#step:3:10)846f8 2025-03-31)`
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7
Backtrace

In this case it is not important, the assertion fails

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at std::os::unix::fs::FileExt::{write_all_at,read_exact_at} and the File::options().append(true) setup in the supplied reproducer; compare behavior on macOS and Linux CI. Check platform documentation and existing standard-library tests for append-mode positional writes. Done means the behavior is correctly documented or fixed, with a regression test if the standard library behavior is wrong.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.