From ce670fe7889b95594291c245abf5ec485541a654 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 10 Aug 2024 07:00:17 +0200 Subject: [PATCH] Check flac magic cookie length --- MP42/MP42AVFImporter.m | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/MP42/MP42AVFImporter.m b/MP42/MP42AVFImporter.m index 3f20aa6..1c9b2ff 100644 --- a/MP42/MP42AVFImporter.m +++ b/MP42/MP42AVFImporter.m @@ -974,13 +974,15 @@ MP42_OBJC_DIRECT_MEMBERS } else if (code == kAudioFormatFLAC || code == kMP42AudioCodecType_FLAC) { - NSMutableData *magicCookie = [NSMutableData dataWithBytes:cookie + 8 length:cookieSizeOut - 8]; - uint8_t *bytes = magicCookie.mutableBytes; - bytes[0] = 'f'; - bytes[1] = 'L'; - bytes[2] = 'a'; - bytes[3] = 'C'; - return magicCookie; + if (cookieSizeOut > 12) { + NSMutableData *magicCookie = [NSMutableData dataWithBytes:cookie + 8 length:cookieSizeOut - 8]; + uint8_t *bytes = magicCookie.mutableBytes; + bytes[0] = 'f'; + bytes[1] = 'L'; + bytes[2] = 'a'; + bytes[3] = 'C'; + return magicCookie; + } } else if (code == kAudioFormatEnhancedAC3) {