diff --git a/fb2k/foo_input_vgmstream.vcxproj b/fb2k/foo_input_vgmstream.vcxproj
index ec4caf19..2d64edc7 100644
--- a/fb2k/foo_input_vgmstream.vcxproj
+++ b/fb2k/foo_input_vgmstream.vcxproj
@@ -97,6 +97,7 @@
%(DelayLoadDLLs)
true
true
+ true
diff --git a/src/coding/mp4_aac_decoder.c b/src/coding/mp4_aac_decoder.c
index 983c865d..6047f925 100644
--- a/src/coding/mp4_aac_decoder.c
+++ b/src/coding/mp4_aac_decoder.c
@@ -44,6 +44,10 @@ void decode_mp4_aac(mp4_aac_codec_data * data, sample * outbuf, int32_t samples_
samples_done += samples_remain;
while ( samples_done < samples_to_do ) {
+ if (data->sampleId >= data->numSamples) {
+ memset(outbuf, 0, (samples_to_do - samples_done) * stream_info->numChannels * sizeof(sample));
+ break;
+ }
if (!MP4ReadSample( data->h_mp4file, data->track_id, ++data->sampleId, (uint8_t**)(&buffer), (uint32_t*)(&buffer_size), 0, 0, 0, 0)) return;
ubuffer_size = buffer_size;
bytes_valid = buffer_size;
diff --git a/src/meta/mp4.c b/src/meta/mp4.c
index 8d4b0a80..8f104856 100644
--- a/src/meta/mp4.c
+++ b/src/meta/mp4.c
@@ -34,8 +34,16 @@ int mp4_file_read( void* handle, void* buffer, int64_t size, int64_t* nin, int64
mp4_streamfile * file = ( mp4_streamfile * ) handle;
int64_t max_size = file->size - file->offset - file->start;
if ( size > max_size ) size = max_size;
- *nin = read_streamfile( (uint8_t *) buffer, file->offset, size, file->streamfile );
- file->offset += *nin;
+ if ( size > 0 )
+ {
+ *nin = read_streamfile( (uint8_t *) buffer, file->offset, size, file->streamfile );
+ file->offset += *nin;
+ }
+ else
+ {
+ *nin = 0;
+ return 1;
+ }
return 0;
}