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

panic on bad APICFrame #28

Closed
thraxil opened this issue Oct 22, 2017 · 1 comment
Closed

panic on bad APICFrame #28

thraxil opened this issue Oct 22, 2017 · 1 comment

Comments

@thraxil
Copy link
Contributor

thraxil commented Oct 22, 2017

I've got a file with a stray null byte at the beginning of the mimetype part of the APICFrame. Attempting to read it causes a panic:

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/dhowden/tag.readAPICFrame(0xc4200102e0, 0xc, 0xc, 0x4, 0x5ef720, 0x0)
         /home/anders/code/go/src/github.com/dhowden/tag/id3v2frames.go:600 +0x55c
github.com/dhowden/tag.readID3v2Frames(0x7fc0a37d2fc0, 0xc42000c028, 0xe9, 0xc42000a100, 
0xc42000c028, 0x0, 0x0)
        /home/anders/code/go/src/github.com/dhowden/tag/id3v2.go:347 +0x796
github.com/dhowden/tag.ReadID3v2Tags(0x5bbac0, 0xc42000c028, 0x1, 0x0, 0x0, 0x0)
        /home/anders/code/go/src/github.com/dhowden/tag/id3v2.go:405 +0xe0
github.com/dhowden/tag.ReadFrom(0x5bbac0, 0xc42000c028, 0xc42000c028, 0x0, 0x0, 0x30)
        /home/anders/code/go/src/github.com/dhowden/tag/tag.go:53 +0x2d2

Digging into it a bit, they bytes being passed into readAPICFrame() are 00 69 6d 61 67 65 2f 6a 70 65 67 00 which is just image/jpeg with a null byte at the beginning and end.

I think the file is invalid so it's fair for the library to refuse to parse it, but it should probably just return an error rather than panicking. It's a pretty simple change to add a if len(b) < 1 check to id3v2frames.go right before line 600.

@dhowden
Copy link
Owner

dhowden commented Oct 22, 2017

Thanks for the report - and the fix!

@dhowden dhowden closed this as completed Oct 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants