AVAudioPlayer initWithContentsOfURL stuck in GetSampleTableBox on 594 bytes audio file

Hello developers,

we have an issue with opening an Apple MPEG-4 audio file that apparently has a correct header but then no actual audio data. This file is 594 bytes and freezes completely the app's main thread and never returns from either of these calls:

NSURL *fileURL = [NSURL fileURLWithPath:filePath];
NSError *error;

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];  // freez (call stack below)

AVAudioFile *audioFile = [[AVAudioFile alloc] initForReading:fileURL error:&error];  // freez

AudioFileID audioFileID;
OSStatus result = AudioFileOpenURL((__bridge CFURLRef)fileURL, kAudioFileReadPermission, 0, &audioFileID);  // freez

Putting the debugger in pause reveals where it is stuck:

#0	0x00007ff81b7683f9 in MP4BoxParser_Track::GetSampleTableBox() ()
#1	0x00007ff81b76785a in MP4BoxParser_Track::GetInfoFromTrackSubBoxes() ()
#2	0x00007ff81b93fde5 in MP4AudioFile::UseAudioTrack(void*, unsigned int, unsigned int) ()
#3	0x00007ff81b93ab2c in MP4AudioFile::OpenFromDataSource() ()
#4	0x00007ff81b72ee85 in AudioFileObject::Open(__CFURL const*, signed char, int) ()
#5	0x00007ff81b72ed9d in AudioFileObject::DoOpen(__CFURL const*, signed char, int) ()
#6	0x00007ff81b72e1f0 in AudioFileOpenURL ()
#7	0x00007ffa382e8183 in -[AVAudioPlayer initWithContentsOfURL:fileTypeHint:error:] ()

With either of 3 calls the call stack is a little bit different but all in the end get stuck forever in MP4BoxParser_Track::GetSampleTableBox()

I'm attaching the incriminated audio file to the post (just rename it back to .m4a):

How can we avoid this and verify that an audio file is openable and playable. Before, we were checking if a file that we belive be an audio contains data inside, if true then we create AVAudioPlayer with it and see if it return no errors and if the duration is >0. This bug breaks this fondamental logic and now we added a hotfix hack to check if the data is at least 600 bytes long. How do we correctly solve this if none of the methods above return any error but instead ALL hang?

AVAudioPlayer initWithContentsOfURL stuck in GetSampleTableBox on 594 bytes audio file
 
 
Q