1
0
mirror of synced 2026-05-22 14:43:19 +00:00

fix(id3v2): prevent crash when no tag frames present

Fix TypeError: Cannot read properties of undefined (reading 'filter') by defaulting missing frame/tag collections to empty arrays/objects.

- Add MP3 sample without tags + regression test
- Update related TS configs and dependencies/lockfile
This commit is contained in:
Borewit
2026-01-28 19:49:43 +01:00
committed by Borewit
parent 0ec4b7e79e
commit 4909b6fe12
3 changed files with 12 additions and 5 deletions
+4 -5
View File
@@ -104,7 +104,7 @@ export class ID3v2Parser {
await (id3Header.flags.isExtendedHeader ? this.parseExtendedHeader() : this.parseId3Data(id3Header.size));
// Post process
const chapters = ID3v2Parser.mapId3v2Chapters(this.metadata.native[this.headerType], this.metadata.format.sampleRate);
const chapters = ID3v2Parser.mapId3v2Chapters(this.metadata.native[this.headerType]);
this.metadata.setFormat('chapters', chapters);
}
@@ -178,10 +178,9 @@ export class ID3v2Parser {
* This function expects the `native` tags already to contain parsed `CHAP` and `CTOC` frame values,
* as produced by `FrameParser.readData`.
*/
private static mapId3v2Chapters(
id3Tags: ITag[],
sampleRate?: number
): IChapter[] | undefined {
private static mapId3v2Chapters(id3Tags?: ITag[]): IChapter[] | undefined {
if (!id3Tags) return;
const chapFrames = id3Tags.filter(t => t.id === 'CHAP') as any[] | undefined;
if (!chapFrames?.length) return;