From f58ef9951f4ae2a362f83c27d53878e955e23b95 Mon Sep 17 00:00:00 2001 From: Patrick Luan Date: Sun, 24 May 2026 17:16:02 -0300 Subject: [PATCH] fix: add codec_name check on isAttachedPic util --- src/utils/mediaUtils.test.ts | 11 +++++++++++ src/utils/mediaUtils.ts | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/utils/mediaUtils.test.ts b/src/utils/mediaUtils.test.ts index 6a3d8b7..9905b79 100644 --- a/src/utils/mediaUtils.test.ts +++ b/src/utils/mediaUtils.test.ts @@ -44,6 +44,17 @@ describe('utils/mediaUtils.ts', () => { expect(isAttachedPic(validVideo)).toBe(false); }); + test('isAttachedPic should handle undefined or malformed codec_name safely', () => { + const malformedStream = { + index: 6, + codec_type: 'video', + codec_name: undefined + } as any; + + expect(() => isAttachedPic(malformedStream)).not.toThrow(); + expect(isAttachedPic(malformedStream)).toBe(false); + }); + test('isGarbageStream should group image subtitles and cover art as garbage', () => { expect(isGarbageStream(imageSubPGS)).toBe(true); expect(isGarbageStream(coverArtAttached)).toBe(true); diff --git a/src/utils/mediaUtils.ts b/src/utils/mediaUtils.ts index 731d7dd..1813010 100644 --- a/src/utils/mediaUtils.ts +++ b/src/utils/mediaUtils.ts @@ -9,7 +9,10 @@ export const isImageSubtitle = (codecName: string | undefined): boolean => { }; export const isAttachedPic = (stream: Pick): boolean => { - return stream.disposition?.attached_pic === 1 || ATTACHED_PIC_CODECS.has(stream.codec_name.toLowerCase()); + return ( + stream.disposition?.attached_pic === 1 || + (!!stream.codec_name && ATTACHED_PIC_CODECS.has(stream.codec_name.toLowerCase())) + ); }; export const isGarbageStream = (stream: MediaStream): boolean => {