Skip to content

AIFF: Error on odd-sized COMT comments #736

Closed

Description

@DistinctBee

Reproducer

I tried this code:

use lofty::config::{ParseOptions, WriteOptions};
use lofty::file::AudioFile;
use lofty::iff::aiff::{AiffFile, AiffTextChunks, Comment};
use lofty::tag::TagExt;

use std::io::Cursor;

fn main() {
      let mut tag = AiffTextChunks::new();
      tag.comments = Some(vec![
              Comment {
                      timestamp: 1024,
                      marker_id: 0,
                      text: String::from("odd"),
              },
              Comment {
                      timestamp: 2048,
                      marker_id: 0,
                      text: String::from("second"),
              },
      ]);

      // An AIFF file holding only the text chunks, as lofty writes them
      let mut aiff = b"FORM\0\0\0\0AIFF".to_vec();
      tag.dump_to(&mut aiff, WriteOptions::default()).unwrap();
      let form_size = (aiff.len() - 8) as u32;
      aiff[4..8].copy_from_slice(&form_size.to_be_bytes());

      let file = AiffFile::read_from(
              &mut Cursor::new(aiff),
              ParseOptions::new().read_properties(false),
      )
      .unwrap();

      assert_eq!(file.text_chunks().unwrap().comments, tag.comments);
}

Output on 0.25.4:

assertion `left == right` failed
  left: Some([Comment { timestamp: 1024, marker_id: 0, text: "odd" }, Comment { timestamp: 8, marker_id: 0, text: "" }])
 right: Some([Comment { timestamp: 1024, marker_id: 0, text: "odd" }, Comment { timestamp: 2048, marker_id: 0, text: "second" }])

The second comment comes back as timestamp 8 with empty text because the reader starts on the pad byte after "odd".

If you change the second comment's marker_id to 7, read_from fails outright instead.

Summary

The AIFF 1.3 Comments Chunk pads each comment's text to an even length, and the pad byte isn't included in its count. create_text_chunks already writes that pad, but the reader doesn't skip it, so every comment following an odd-sized one is read one byte early. Depending on the bytes, that either returns garbage or fails to read the entire file (failed to fill whole buffer) in every parsing mode. Lofty cannot read back its own output.

The existing fixture doesn't catch this, since its only odd-sized comment is the last one, and that pad byte gets skipped as leftover chunk content.

Expected behavior

The assertion in the reproducer doesn't fail (in the marker_id: 7 variant, too).

Assets

No response

Activity

  1. added
    bug
    on Oct 6, 2026
  2. added this to the 0.25.5 milestone on Oct 6, 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