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

Address infinite loops while reading ID3v2 tags. #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LorenVS
Copy link

@LorenVS LorenVS commented Feb 4, 2025

The Buffer.read() call will infinitely loop if the number of bytes remaining in the file is less than the requested size. A large number of read() calls in ID3v2Parser are at risk of infinitely looping on malformed files. I'm changing Buffer to throw an exception when it detects there are no more bytes to read from the file.

There is a more egregious case with the potential Xing header. The parser blindly reads 1500 bytes to search for the header, but there is no guarantee (even in a well-formed file) that there will be 1500 more bytes remaining to be read. I'm introducing a readAtMost method to Buffer which will handle cases where there are fewer than size bytes remaining in the file.

I'm also updating some of the logic which is checking for the start of the Xing header to be safer, checking to ensure that there are enough bytes remaining to parse the data from this header.

This is a partial fix for #47. I only looked at the first (mp3) case. The second (ogg) case might be unrelated.

The `Buffer.read()` call will infinitely loop if the number of bytes
remaining in the file is less than the requested size. A large number of
`read()` calls in `ID3v2Parser` are at risk of infinitely looping on
malformed files. I'm changing `Buffer` to throw an exception when it
detects there are no more bytes to read from the file.

There is a more egregious case with the potential `Xing` header. The
parser blindly reads 1500 bytes to search for the header, but there is
no guarantee (even in a well-formed file) that there will be 1500 more
bytes remaining to be read. I'm introducing a `readAtMost` method to
`Buffer` which will handle cases where there are fewer than `size` bytes
remaining in the file.

I'm also updating some of the logic which is checking for the start of
the `Xing` header to be safer, checking to ensure that there are enough
bytes remaining to parse the data from this header.
@ClementBeal
Copy link
Owner

Thank you for your PR! I'm going to review it soon.

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

Successfully merging this pull request may close these issues.

2 participants