From 3127636c4218922b310cb47ec37ef1b3755fd868 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Mon, 9 Sep 2024 23:54:24 -0400 Subject: [PATCH] fix(server): handle invalid directory item (#12534) --- server/src/services/metadata.service.spec.ts | 10 ++++++++++ server/src/services/metadata.service.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/services/metadata.service.spec.ts b/server/src/services/metadata.service.spec.ts index 8e865bd20f..ad07c2595f 100644 --- a/server/src/services/metadata.service.spec.ts +++ b/server/src/services/metadata.service.spec.ts @@ -520,6 +520,16 @@ describe(MetadataService.name, () => { ); }); + it('should handle an invalid Directory Item', async () => { + assetMock.getByIds.mockResolvedValue([assetStub.image]); + metadataMock.readTags.mockResolvedValue({ + MotionPhoto: 1, + ContainerDirectory: [{ Foo: 100 }], + }); + + await expect(sut.handleMetadataExtraction({ id: assetStub.image.id })).resolves.toBe(JobStatus.SUCCESS); + }); + it('should extract the correct video orientation', async () => { assetMock.getByIds.mockResolvedValue([assetStub.video]); mediaMock.probe.mockResolvedValue(probeStub.videoStreamVertical2160p); diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts index 83f0abd79b..9a4362daca 100644 --- a/server/src/services/metadata.service.ts +++ b/server/src/services/metadata.service.ts @@ -428,7 +428,7 @@ export class MetadataService { if (isMotionPhoto && directory) { for (const entry of directory) { - if (entry.Item.Semantic == 'MotionPhoto') { + if (entry?.Item?.Semantic == 'MotionPhoto') { length = entry.Item.Length ?? 0; padding = entry.Item.Padding ?? 0; break;