Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e52267ad authored by Joshua J. Drake's avatar Joshua J. Drake
Browse files

Prevent divide by zero in WAVExtractor

In the case that mNumChannels, bytesPerSample, or mSampleRate are
zero, a divide by zero occurs. None of these parameters of a WAV
file should ever be zero. Check that they aren't and return an error
otherwise.

Bug: 23285883

Change-Id: Id67b8620944405ca59572221f6f1c2b19c363e69
parent e1d095fa
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -311,9 +311,17 @@ status_t WAVExtractor::init() {
                        1000000LL * (mDataSize / 65 * 320) / 8000;
                } else {
                    size_t bytesPerSample = mBitsPerSample >> 3;

                    if (!bytesPerSample || !mNumChannels)
                        return ERROR_MALFORMED;

                    size_t num_samples = mDataSize / (mNumChannels * bytesPerSample);

                    if (!mSampleRate)
                        return ERROR_MALFORMED;

                    durationUs =
                        1000000LL * (mDataSize / (mNumChannels * bytesPerSample))
                            / mSampleRate;
                        1000000LL * num_samples / mSampleRate;
                }

                mTrackMeta->setInt64(kKeyDuration, durationUs);