Skip to content

AIFF save panic: out-of-range slice in Vec when rewriting text chunks (range end index ... out of range) #619

Closed

Description

@ijobava

Reproducer

use lofty::config::{ParseOptions, ParsingMode, WriteOptions};
use lofty::file::AudioFile;
use lofty::iff::aiff::AiffFile;
use lofty::probe::Probe;

fn main() {
    // Put the problematic AIFF next to this Cargo.toml, or pass path as arg.
    let arg_path = std::env::args().nth(1);
    let source = arg_path.unwrap_or_else(|| "..\\Kobosil - Bei Nacht H (178).aiff".to_string());

    let source_path = std::path::PathBuf::from(&source);
    if !source_path.exists() {
        eprintln!("file not found: {}", source_path.display());
        std::process::exit(2);
    }

    // Work on temp copy.
    let temp = std::env::temp_dir().join("lofty_aiff_panic_repro.aiff");
    std::fs::copy(&source_path, &temp).expect("copy failed");

    let mut file = std::fs::File::options()
        .read(true)
        .write(true)
        .open(&temp)
        .expect("open failed");

    let parse_options = ParseOptions::new()
        .parsing_mode(ParsingMode::BestAttempt)
        .read_cover_art(true)
        .implicit_conversions(false);

    let probe = Probe::new(&mut file)
        .options(parse_options)
        .guess_file_type()
        .expect("probe failed");

    let mut aiff = AiffFile::read_from(probe.into_inner(), parse_options).expect("AIFF read failed");
    let mut text = aiff.text_chunks().cloned().unwrap_or_default();
    text.name = Some("UAT_DIRECT_LOFTY_TITLE".to_string());
    aiff.set_text_chunks(text);

    // Panic is observed here for the problematic sample.
    aiff.save_to(&mut file, WriteOptions::default())
        .expect("save failed");

    println!("save succeeded: {}", temp.display());
}

Summary

Command:
cargo run -q -p uat_cli --bin lofty_aiff_direct_repro -- "D:\Music\ΝEW\ΜDBU\yshar38\TECHNO\Kobosil - Bei Nacht H (178).aiff"

Observed panic:
thread 'main' panicked at ...\alloc\src\vec\mod.rs:2852:36:
range end index 81507680 out of range for slice of length 81507679

Notes:

  • Read succeeds.
  • Mutation succeeds.
  • Panic happens on save_to(...).

Expected behavior

No response

Assets

https://drive.google.com/file/d/1lr6vY1p8caPSc0A-2WnM46XNO2sMT70e/view?usp=sharing

Activity

  1. added
    bug
    on Feb 18, 2026
  2. added this to the 0.23.3 milestone on Feb 19, 2026
  3. Serial-ATA commented on Feb 19, 2026

    @Serial-ATA
    Owner

    Interesting, the ID3v2 chunk has padding but it's included in the chunk size which isn't valid per the spec (https://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/AIFF/Docs/AIFF-1.3.pdf):

    If the data is an odd number of bytes in length, a zero pad byte must be added at the end. The pad
    byte is not included in ckSize .

    Right now, it's assumed that the padding is correct so we just blindly try to skip it, but end up going outside of the bounds of the file data:

    // We need to remove the padding byte if it exists
    if existing_id3_size % 2 != 0 {
    existing_id3_size += 1;
    }

    I'll try to come up with some hack to detect this.

  4. changed the title [-]IFF save panic: out-of-range slice in Vec when rewriting text chunks (range end index ... out of range)[/-] [+]AIFF save panic: out-of-range slice in Vec when rewriting text chunks (range end index ... out of range)[/+] on Feb 22, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions