Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix id3v2 sum error #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,31 @@ func SumID3v1(r io.ReadSeeker) (string, error) {
// SumID3v2 constructs a checksum of MP3 audio file data (assumed to have ID3v2 tags) provided by the
// io.ReadSeeker which is metadata invariant.
func SumID3v2(r io.ReadSeeker) (string, error) {
header, _, err := readID3v2Header(r)
header, offset, err := readID3v2Header(r)
if err != nil {
return "", fmt.Errorf("error reading ID3v2 header: %v", err)
}

_, err = r.Seek(int64(header.Size), io.SeekCurrent)
endOffset := int64(128)
n, err := r.Seek(-endOffset, io.SeekEnd)
if err != nil {
return "", fmt.Errorf("error seeking to end of ID3V2 header: %v", err)
return "", fmt.Errorf("error seeking end offset (%d bytes): %v", endOffset, err)
}
tag, err := readString(r, 3)
if err != nil {
return "", fmt.Errorf("error checking ID3v1: %w", err)
}
// seek to end if id3v1 does not exist
if tag != "TAG" {
n += endOffset
}

n, err := sizeToEndOffset(r, 128)
start := int64(offset + header.Size)
_, err = r.Seek(start, io.SeekStart)
if err != nil {
return "", fmt.Errorf("error determining read size to ID3v1 header: %v", err)
return "", fmt.Errorf("error seeking to end of ID3V2 header: %v", err)
}
n -= start

// TODO: remove this check?????
if n < 0 {
Expand Down