Skip to content

Commit

Permalink
Bug 1563949 - part3 : handle invalid sample in demuxer. r=jya
Browse files Browse the repository at this point in the history
Return demux error when we get a invalid sample. For mp4 demuxer, we use `MOZ_DIAGNOSTIC_ASSERT` instead because we are pretty sure that it won't happen.

Differential Revision: https://phabricator.services.mozilla.com/D38553

--HG--
extra : moz-landing-system : lando
  • Loading branch information
alastor0325 committed Jul 19, 2019
1 parent 424b48c commit 44cfc79
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
10 changes: 7 additions & 3 deletions dom/media/flac/FlacDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ class FrameHeader {
}
mValid =
#ifdef FUZZING
true;
#else
crc == br.ReadBits(8);
true;
#else
crc == br.ReadBits(8);
#endif
mSize = br.BitCount() / 8;

Expand Down Expand Up @@ -813,6 +813,10 @@ RefPtr<FlacTrackDemuxer::SamplesPromise> FlacTrackDemuxer::GetSamples(
while (aNumSamples--) {
RefPtr<MediaRawData> frame(GetNextFrame(FindNextFrame()));
if (!frame) break;
if (!frame->HasValidTime()) {
return SamplesPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
__func__);
}
frames->AppendSample(frame);
}

Expand Down
18 changes: 15 additions & 3 deletions dom/media/hls/HLSDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ RefPtr<HLSTrackDemuxer::SamplesPromise> HLSTrackDemuxer::DoGetSamples(
if (!mrd) {
return SamplesPromise::CreateAndReject(NS_ERROR_OUT_OF_MEMORY, __func__);
}
if (!mrd->HasValidTime()) {
return SamplesPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
__func__);
}
samples->AppendSample(mrd);
}
if (mType == TrackInfo::kVideoTrack &&
Expand Down Expand Up @@ -569,11 +573,19 @@ HLSTrackDemuxer::DoSkipToNextRandomAccessPoint(const TimeUnit& aTimeThreshold) {
if (sample->IsKeyFrame()) {
java::sdk::BufferInfo::LocalRef info = sample->Info();
int64_t presentationTimeUs = 0;
bool ok = NS_SUCCEEDED(info->PresentationTimeUs(&presentationTimeUs));
if (ok &&
if (NS_SUCCEEDED(info->PresentationTimeUs(&presentationTimeUs)) &&
TimeUnit::FromMicroseconds(presentationTimeUs) >= aTimeThreshold) {
RefPtr<MediaRawData> rawData = ConvertToMediaRawData(sample);
if (!rawData) {
result = NS_ERROR_OUT_OF_MEMORY;
break;
}
if (!rawData->HasValidTime()) {
result = NS_ERROR_DOM_MEDIA_DEMUXER_ERR;
break;
}
found = true;
mQueuedSample = ConvertToMediaRawData(sample);
mQueuedSample = rawData;
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions dom/media/mp3/MP3Demuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ RefPtr<MP3TrackDemuxer::SamplesPromise> MP3TrackDemuxer::GetSamples(
if (!frame) {
break;
}
if (!frame->HasValidTime()) {
return SamplesPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
__func__);
}
frames->AppendSample(frame);
}

Expand Down
3 changes: 3 additions & 0 deletions dom/media/mp4/MP4Demuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ RefPtr<MP4TrackDemuxer::SeekPromise> MP4TrackDemuxer::Seek(
continue;
}
if (sample->mKeyframe) {
MOZ_DIAGNOSTIC_ASSERT(sample->HasValidTime());
mQueuedSample = sample;
seekTime = mQueuedSample->mTime;
}
Expand Down Expand Up @@ -500,6 +501,7 @@ RefPtr<MP4TrackDemuxer::SamplesPromise> MP4TrackDemuxer::GetSamples(
if (!sample->Size()) {
continue;
}
MOZ_DIAGNOSTIC_ASSERT(sample->HasValidTime());
samples->AppendSample(sample);
aNumSamples--;
}
Expand Down Expand Up @@ -561,6 +563,7 @@ MP4TrackDemuxer::SkipToNextRandomAccessPoint(
RefPtr<MediaRawData> sample;
while (!found && (sample = GetNextSample())) {
parsed++;
MOZ_DIAGNOSTIC_ASSERT(sample->HasValidTime());
if (sample->mKeyframe && sample->mTime >= aTimeThreshold) {
found = true;
mQueuedSample = sample;
Expand Down
4 changes: 4 additions & 0 deletions dom/media/ogg/OggDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,10 @@ RefPtr<OggTrackDemuxer::SamplesPromise> OggTrackDemuxer::GetSamples(
if (!sample) {
break;
}
if (!sample->HasValidTime()) {
return SamplesPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
__func__);
}
samples->AppendSample(sample);
aNumSamples--;
}
Expand Down
4 changes: 4 additions & 0 deletions dom/media/wave/WaveDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ RefPtr<WAVTrackDemuxer::SamplesPromise> WAVTrackDemuxer::GetSamples(
if (!datachunk) {
break;
}
if (!datachunk->HasValidTime()) {
return SamplesPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
__func__);
}
datachunks->AppendSample(datachunk);
}

Expand Down
4 changes: 4 additions & 0 deletions dom/media/webm/WebMDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,10 @@ RefPtr<WebMTrackDemuxer::SamplesPromise> WebMTrackDemuxer::GetSamples(
if (mNeedKeyframe && !sample->mKeyframe) {
continue;
}
if (!sample->HasValidTime()) {
return SamplesPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
__func__);
}
mNeedKeyframe = false;
samples->AppendSample(sample);
aNumSamples--;
Expand Down

0 comments on commit 44cfc79

Please sign in to comment.