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

parseFile error: Buffer length must be even #979

Closed
JL102 opened this issue Jan 17, 2022 · 5 comments · Fixed by #982
Closed

parseFile error: Buffer length must be even #979

JL102 opened this issue Jan 17, 2022 · 5 comments · Fixed by #982

Comments

@JL102
Copy link

JL102 commented Jan 17, 2022

Bug description
This was originally discovered by a user of MediaMonkeyServer (https://github.com/mediamonkeyserver/mms/): https://www.mediamonkey.com/forum/viewtopic.php?t=101151
Upon calling mm.parseFile for certain music files, the promise is rejected with the following error message: Uncaught Error: Buffer length must be even

Expected behavior
N/A (The promise is rejected, so we don't get the metadata)

Reproduction example & stack trace

> mm.parseFile('./Alexander Hacke (Sanctuary) - 01 Minnie & Me.mp3')
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 246,
  [Symbol(trigger_async_id_symbol)]: 5,
  [Symbol(destroyed)]: { destroyed: false }
}
> Uncaught Error: Buffer length must be even
    at swapBytes (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\common\Util.js:44:15)
    at Object.decodeString (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\common\Util.js:72:29)
    at FrameParser.readData (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\id3v2\FrameParser.js:91:35)
    at Function.readFrameData (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\id3v2\ID3v2Parser.js:64:36)
    at ID3v2Parser.parseMetadata (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\id3v2\ID3v2Parser.js:158:40)
    at ID3v2Parser.parseId3Data (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\id3v2\ID3v2Parser.js:113:32)
    at async MpegParser.tryReadId3v2Headers (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\id3v2\AbstractID3Parser.js:55:13)
    at async MpegParser.parseID3v2 (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\id3v2\AbstractID3Parser.js:39:9)
    at async MpegParser.parse (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\id3v2\AbstractID3Parser.js:24:13)
    at async Function._parse (C:\Users\draki\Downloads\Sanctuary\node_modules\music-metadata\lib\ParserFactory.js:160:9)> mm.parseFile('./Alexander Hacke (Sanctuary) - 02 Sister.mp3')

Audio file demonstrating the problem
If applicable, please drag and drop the zipped audio file(s) which caused the problem into the bug report.
Please create additional issues if you experience different problems for each file.
Sanctuary.zip

I attempted to manually edit one metadata item at a time (using Windows' built-in music properties editor) to see if manually "refreshing" one of the values would stop the errors from occurring, but with no luck.

@Borewit
Copy link
Owner

Borewit commented Jan 17, 2022

Thanks for reporting the issue @JL102

The ID3v2.3 TLEN field has invalid encoded 16 bit unicode string. It seems to have an extra 00 between the BOM field and the octets representing the string value.

I will prevent the error from being throws and capture this in the returned quality.warnings.

Borewit added a commit that referenced this issue Jan 17, 2022
Register a warning instead of a fatal error.

Resolves #979
Borewit added a commit that referenced this issue Jan 17, 2022
Register a warning instead of a fatal error.

Resolves #979
@JL102
Copy link
Author

JL102 commented Jan 18, 2022

Working, thank you!

@Kyant0
Copy link

Kyant0 commented Nov 1, 2023

Is this TLEN field informal or invalid? Do all of the TLEN has invalid utf-16 string? Or can the workaround be approved in such case? I can't find there is a standard regarding it.

@Kyant0
Copy link

Kyant0 commented Nov 1, 2023

And the encoding of the TLEN field is UTF-16 (LE), but the BOM of UTF-16 BE (0xFEFF) is used.

@Borewit
Copy link
Owner

Borewit commented Nov 1, 2023

Do all of the TLEN has invalid utf-16 string?

No this is very exceptional, most encoders comply with the standard.

But maybe you mean: is any TLEN field with an UTF-16 string invlid?

Absolutely, should be ISO-8859-1.
BOM fields do not belong in this field, neither in any other field in ID3.

I can't find there is a standard regarding it.

Both for id3v2.3.0 & id3v2.4.0:

TLEN The ‘Length’ frame contains the length of the audiofile in milliseconds, represented as a numeric string.

id3v2.3.0:

All numeric strings and URLs [URL] are always encoded as ISO-8859-1.

id3v2.4.0:

If nothing else is said, strings, including numeric strings and URLs [URL], are represented as ISO-8859-1 [ISO-8859-1] characters in the range $20 - $FF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants