bevyengine/bevy · error · std::io::Error

InvalidInput

InvalidInput

Error message

seek position is out of range

What it means

slice_seek returns an io::Error 'seek position is out of range' when the requested SeekFrom position resolves outside the byte slice being read (e.g. a negative offset before 0 or a position past the end). The slice-backed reader cannot seek beyond its data.

Source

Thrown at crates/bevy_asset/src/io/mod.rs:730

/// Performs a read from the `slice` into `buf`.
pub(crate) fn slice_read(slice: &[u8], bytes_read: &mut usize, buf: &mut [u8]) -> usize {
    if *bytes_read >= slice.len() {
        0
    } else {
        let n = std::io::Read::read(&mut &slice[(*bytes_read)..], buf).unwrap();
        *bytes_read += n;
        n
    }
}

/// Performs a "seek" and updates the cursor of `bytes_read`. Returns the new byte position.
pub(crate) fn slice_seek(
    slice: &[u8],
    bytes_read: &mut usize,
    pos: SeekFrom,
) -> std::io::Result<u64> {
    let make_error = || {
        Err(std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            "seek position is out of range",
        ))
    };
    let (origin, offset) = match pos {
        SeekFrom::Current(offset) => (*bytes_read, Ok(offset)),
        SeekFrom::Start(offset) => (0, offset.try_into()),
        SeekFrom::End(offset) => (slice.len(), Ok(offset)),
    };
    let Ok(offset) = offset else {
        return make_error();
    };
    let Ok(origin): Result<i64, _> = origin.try_into() else {
        return make_error();
    };
    let Ok(new_pos) = (origin + offset).try_into() else {
        return make_error();
    };

View on GitHub (pinned to 396ca72708)

Solutions

  1. Clamp or validate seek offsets against the reader's length before seeking
  2. Compute positions from the current cursor and total length instead of absolute guesses
  3. Handle the io error and skip the seek for optional seek-based parsing paths
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/bevy_asset/src/io/mod.rs:730 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/9facc8acf429a64f. Report an issue: GitHub.