Skip to content

Real and potential bugs, found by claude code #656

Closed

Description

@qarmin

Reproducer

No response

Summary

Recently during project check, I found that Claude Code found some real and some potential, bugs in this project.

Due to limited knowing of audio metadata, I was only able to validate only some bugs, which I added below

1. remove_disk_total() uses self.track() instead of self.disk()

lofty/src/id3/v2/tag.rs:749

fn remove_disk_total(&mut self) {
    let existing_track_number = self.track(); // BUG: should be self.disk()

When removing the disc total, the method reads the track number and writes it as the disc number into TPOS. Silent metadata corruption.

Image

2. TagRestrictions::from_byte() — wrong bitmask 0x0C instead of 0xC0

lofty/src/id3/v2/restrictions.rs:71

// Comment says: xx000000 (bits 6-7)
match restriction_flags & 0x0C {  // 0x0C = 00001100, should be 0xC0 = 11000000
    64 => ...  // will never match, because 0x0C masks bits 2-3

Values 64/128/192 will never match after masking with 0x0C. Tag size restrictions are always silently ignored. Similarly as_bytes() at line 116 writes 0x0C instead of 0xC0 for S_32F_4K.


19. set_genre on Id3v1Tag — silent no-op for unknown genres

lofty/src/id3/v1/tag.rs:147-156
If the genre string does not match any of the 192 predefined genres, the old genre is not cleared and no error is returned. The user gets no indication their set_genre call did nothing.


The full report, you can find here - findings.md

Expected behavior

No response

Assets

No response

Activity

  1. added
    bug
    on May 9, 2026
  2. Serial-ATA commented on May 9, 2026

    @Serial-ATA
    Owner

    Thankfully these are mostly in obscure features or just unrealistic edge cases.

    6 - It even mentions that the truncation is guarded, so ???
    12 - Errors are being redone in the https://github.com/Serial-ATA/lofty-rs/tree/errors branch, this doesn't exist anymore
    14 - Realistically, I don't see this being a big deal unless there's benchmarks proving otherwise
    15 - Slowly making this better over time, that's just the easiest approach. I used to have "smarter" in-place writes for FLAC but that ended up problematic (#549, #640), so I just reverted back to the "read everything and sort it out in memory" approach for now. There's also #445 which applies here
    16 - Same as 15. I'm aware of this, just haven't gotten around to making it better
    17 - Ditto
    19 - Accessor methods don't return errors intentionally. You can interact with tags in a generic way, but it's not guaranteed that it actually supports that field or specific input. Whether or not it should clear the genre, I'm not sure
    20 - Most of those assertions aren't user-controlled, and any that are have panic docs
    21 - That's intentional

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions