From a33fcd02a0902bf46328cc849c617633d8d951df Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Thu, 18 Feb 2016 13:25:40 +0100 Subject: [PATCH] Fix leaks and read the webvtt magic cookie from mp4. --- MP42/MP42AVFImporter.m | 2 +- MP42/MP42AudioTrack.m | 2 +- MP42/MP42FormatUtilites.mm | 12 +++++++++++- MP42/MP42Mp4Importer.m | 16 ++++++++++++++++ MP42Foundation.xcodeproj/project.pbxproj | 4 ++-- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/MP42/MP42AVFImporter.m b/MP42/MP42AVFImporter.m index b11d9bf..ec58468 100644 --- a/MP42/MP42AVFImporter.m +++ b/MP42/MP42AVFImporter.m @@ -926,7 +926,7 @@ int pos = 0; for (int i = 0; i < samplesNum; i++) { CMSampleTimingInfo sampleTimingInfo; - CMTime decodeTimeStamp; + __unused CMTime decodeTimeStamp; CMTime presentationTimeStamp; CMTime presentationOutputTimeStamp = CMSampleBufferGetOutputPresentationTimeStamp(sampleBuffer); diff --git a/MP42/MP42AudioTrack.m b/MP42/MP42AudioTrack.m index 896e344..70d98a2 100644 --- a/MP42/MP42AudioTrack.m +++ b/MP42/MP42AudioTrack.m @@ -75,8 +75,8 @@ extern u_int8_t MP4AV_AacConfigGetChannels(u_int8_t* pConfig); uint8_t *ppValue; uint32_t pValueSize; MP4GetTrackBytesProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.ec-3.dec3.content", &ppValue, &pValueSize); - readEAC3Config(ppValue, pValueSize, &_channels, &_channelLayoutTag); + free(ppValue); } else if (MP4HaveTrackAtom(fileHandle, _trackId, "mdia.minf.stbl.stsd.alac")) { uint64_t channels_count = 0; diff --git a/MP42/MP42FormatUtilites.mm b/MP42/MP42FormatUtilites.mm index 4fd76cb..6f61005 100644 --- a/MP42/MP42FormatUtilites.mm +++ b/MP42/MP42FormatUtilites.mm @@ -649,6 +649,7 @@ int analyze_EAC3(void **context ,uint8_t *frame, uint32_t size) if (!info->ec3_done) { /* AC-3 substream must be the first one */ if (hdr->bitstream_id <= 10 && hdr->substreamid != 0) { + free(hdr); return -1; } @@ -657,11 +658,13 @@ int analyze_EAC3(void **context ,uint8_t *frame, uint32_t size) if (hdr->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) { /* substream ids must be incremental */ if (hdr->substreamid > info->num_ind_sub + 1) { + free(hdr); return -1; } if (hdr->substreamid == info->num_ind_sub + 1) { //info->num_ind_sub++; + free(hdr); return -1; } else if (hdr->substreamid < info->num_ind_sub || (hdr->substreamid == 0 && info->substream[0].bsid)) { @@ -720,6 +723,8 @@ int analyze_EAC3(void **context ,uint8_t *frame, uint32_t size) concatenate: + free(hdr); + if (!info->num_blocks && num_blocks == 6) { return size; } @@ -790,5 +795,10 @@ CFDataRef createCookie_EAC3(void *context) free(info->frame); - return CFDataCreate(kCFAllocatorDefault, cookie.GetBuffer(), cookie.GetBitPosition() / 8); + uint8_t *buffer = cookie.GetBuffer(); + size_t size = cookie.GetBitPosition() / 8; + CFDataRef cookieData = CFDataCreate(kCFAllocatorDefault, buffer, size); + free (buffer); + + return cookieData; } diff --git a/MP42/MP42Mp4Importer.m b/MP42/MP42Mp4Importer.m index 9eafa95..0081a4c 100644 --- a/MP42/MP42Mp4Importer.m +++ b/MP42/MP42Mp4Importer.m @@ -112,6 +112,7 @@ uint32_t pValueSize; MP4GetTrackBytesProperty(_fileHandle, srcTrackId, "mdia.minf.stbl.stsd.ec-3.dec3.content", &ppValue, &pValueSize); magicCookie = [NSData dataWithBytes:ppValue length:pValueSize]; + free(ppValue); } } else if (!strcmp(media_data_name, "alac")) { @@ -120,6 +121,7 @@ uint32_t pValueSize; MP4GetTrackBytesProperty(_fileHandle, srcTrackId, "mdia.minf.stbl.stsd.alac.alac.AppleLosslessMagicCookie", &ppValue, &pValueSize); magicCookie = [NSData dataWithBytes:ppValue length:pValueSize]; + free(ppValue); } } else { @@ -233,6 +235,20 @@ } } + else if ((!strcasecmp(trackType, MP4_TEXT_TRACK_TYPE))) { + + if (!strcmp(media_data_name, "wvtt")) { + if (MP4HaveTrackAtom(_fileHandle, srcTrackId, "mdia.minf.stbl.stsd.wvtt.vttC")) { + uint8_t *ppValue; + uint32_t pValueSize; + MP4GetTrackBytesProperty(_fileHandle, srcTrackId, "mdia.minf.stbl.stsd.wvtt.vttC.config", &ppValue, &pValueSize); + magicCookie = [NSData dataWithBytes:ppValue length:pValueSize]; + free(ppValue); + return magicCookie; + } + } + } + return nil; } diff --git a/MP42Foundation.xcodeproj/project.pbxproj b/MP42Foundation.xcodeproj/project.pbxproj index b39922d..4c93056 100644 --- a/MP42Foundation.xcodeproj/project.pbxproj +++ b/MP42Foundation.xcodeproj/project.pbxproj @@ -134,7 +134,7 @@ A9B9C27D1823923200416A4E /* MP42FileImporter.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C2321823923100416A4E /* MP42FileImporter.h */; settings = {ATTRIBUTES = (Public, ); }; }; A9B9C27E1823923200416A4E /* MP42FileImporter.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C2331823923100416A4E /* MP42FileImporter.m */; }; A9B9C27F1823923200416A4E /* MP42H264Importer.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C2341823923100416A4E /* MP42H264Importer.h */; }; - A9B9C2801823923200416A4E /* MP42H264Importer.mm in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C2351823923100416A4E /* MP42H264Importer.mm */; settings = {COMPILER_FLAGS = "-w"; }; }; + A9B9C2801823923200416A4E /* MP42H264Importer.mm in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C2351823923100416A4E /* MP42H264Importer.mm */; settings = {COMPILER_FLAGS = "-w -Xanalyzer -analyzer-disable-all-checks"; }; }; A9B9C2811823923200416A4E /* MP42HtmlParser.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C2361823923100416A4E /* MP42HtmlParser.h */; }; A9B9C2821823923200416A4E /* MP42HtmlParser.m in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C2371823923100416A4E /* MP42HtmlParser.m */; }; A9B9C2831823923200416A4E /* MP42Image.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C2381823923100416A4E /* MP42Image.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -174,7 +174,7 @@ A9B9C2A61823923200416A4E /* downmix.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C25C1823923200416A4E /* downmix.h */; }; A9B9C2A71823923200416A4E /* MatroskaFile.c in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C25D1823923200416A4E /* MatroskaFile.c */; }; A9B9C2A81823923200416A4E /* MatroskaFile.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C25E1823923200416A4E /* MatroskaFile.h */; }; - A9B9C2A91823923200416A4E /* MatroskaParser.c in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C25F1823923200416A4E /* MatroskaParser.c */; settings = {COMPILER_FLAGS = "-w"; }; }; + A9B9C2A91823923200416A4E /* MatroskaParser.c in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C25F1823923200416A4E /* MatroskaParser.c */; settings = {COMPILER_FLAGS = "-w -Xanalyzer -analyzer-disable-all-checks"; }; }; A9B9C2AA1823923200416A4E /* MatroskaParser.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C2601823923200416A4E /* MatroskaParser.h */; }; A9B9C2AB1823923200416A4E /* mbs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9B9C2611823923200416A4E /* mbs.cpp */; }; A9B9C2AC1823923200416A4E /* mbs.h in Headers */ = {isa = PBXBuildFile; fileRef = A9B9C2621823923200416A4E /* mbs.h */; };