Skip to content

[BUG]: read_bytes() function reads a maximum file size of 2GB when the size argument is specified #1622

Done

Description

@MoSafi2

Bug description

As per the title.
When the read_bytes() function is invoked on a FileHandle, it can read the whole file until EOF. However, when the size is specified, the maximum size that can be read is 1.99GB (2,147,479,552 bytes; closer to the max size representation of Int32), although the size argument itself should have a Int64 type.

Steps to reproduce

fn main() raises:
    let path ="/path/to/huge/file.(tar.gz, fastq)"
    let handle = open(path, "r")
    let chunk = handle.read_bytes(SIMD[DType.int64, 1](8*1024*1024*1024))
    print(chunk)

Tensor([[31, -117, 8, ..., -40, 125, 127]], dtype=int8, shape=2147479552)

I tried with a few filetypes (archives and plain text files) and the resut is the same

System information

- What OS did you do install Mojo on ? WSL2, also replicable on Ubuntu 22.04
- Provide version information for Mojo by pasting the output of `mojo -v`: mojo 0.6.1 (876ded2e)
- Provide Modular CLI version by pasting the output of `modular -v`: modular 0.2.0 (355ea9c0)

Activity

  1. added
    bug
    mojo
    on Jan 15, 2024
  2. added
    mojo-stdlib
    on Jan 15, 2024
  3. added
    mojo-repo
    on Apr 29, 2024
  4. added
    mojo-stdlib
    and removed
    mojo-stdlib
    on May 3, 2024
  5. NathanSWard commented on Dec 1, 2026

    @NathanSWard
    Contributor

    Thanks for reporting, @MoSafi2! read_bytes now keeps reading until it has the requested size, and @Alex-Wengg fixed the remaining macOS failure for reads over 2 GiB in #7617; on a current build of main, read_bytes(2_300_000_000) returns all 2.3 GB. The fix is in nightly builds and will ship in the next stable release, so I'm closing this.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmojomojo-repomojo-stdlib

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions