mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
WAV: Don't read past data end position
Issue: #7129 PiperOrigin-RevId: 302660343
This commit is contained in:
parent
134df9fb71
commit
05fb211121
4 changed files with 17 additions and 5 deletions
|
|
@ -99,6 +99,8 @@
|
||||||
costly on large files.
|
costly on large files.
|
||||||
* MP4: Store the Android capture frame rate only in `Format.metadata`.
|
* MP4: Store the Android capture frame rate only in `Format.metadata`.
|
||||||
`Format.frameRate` now stores the calculated frame rate.
|
`Format.frameRate` now stores the calculated frame rate.
|
||||||
|
* WAV: Fix failure to play WAV files that contain trailing non-media bytes
|
||||||
|
([#7129](https://github.com/google/ExoPlayer/issues/7129))
|
||||||
* Testing
|
* Testing
|
||||||
* Upgrade Truth dependency from 0.44 to 1.0.
|
* Upgrade Truth dependency from 0.44 to 1.0.
|
||||||
* Upgrade to JUnit 4.13-rc-2.
|
* Upgrade to JUnit 4.13-rc-2.
|
||||||
|
|
|
||||||
|
|
@ -252,14 +252,14 @@ public final class WavExtractor implements Extractor {
|
||||||
@Override
|
@Override
|
||||||
public boolean sampleData(ExtractorInput input, long bytesLeft) throws IOException {
|
public boolean sampleData(ExtractorInput input, long bytesLeft) throws IOException {
|
||||||
// Write sample data until we've reached the target sample size, or the end of the data.
|
// Write sample data until we've reached the target sample size, or the end of the data.
|
||||||
boolean endOfSampleData = bytesLeft == 0;
|
while (bytesLeft > 0 && pendingOutputBytes < targetSampleSizeBytes) {
|
||||||
while (!endOfSampleData && pendingOutputBytes < targetSampleSizeBytes) {
|
|
||||||
int bytesToRead = (int) Math.min(targetSampleSizeBytes - pendingOutputBytes, bytesLeft);
|
int bytesToRead = (int) Math.min(targetSampleSizeBytes - pendingOutputBytes, bytesLeft);
|
||||||
int bytesAppended = trackOutput.sampleData(input, bytesToRead, true);
|
int bytesAppended = trackOutput.sampleData(input, bytesToRead, true);
|
||||||
if (bytesAppended == RESULT_END_OF_INPUT) {
|
if (bytesAppended == RESULT_END_OF_INPUT) {
|
||||||
endOfSampleData = true;
|
bytesLeft = 0;
|
||||||
} else {
|
} else {
|
||||||
pendingOutputBytes += bytesAppended;
|
pendingOutputBytes += bytesAppended;
|
||||||
|
bytesLeft -= bytesAppended;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,7 +281,7 @@ public final class WavExtractor implements Extractor {
|
||||||
pendingOutputBytes = offset;
|
pendingOutputBytes = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return endOfSampleData;
|
return bytesLeft <= 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.extractor.wav;
|
package com.google.android.exoplayer2.extractor.wav;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -30,7 +31,16 @@ public final class WavExtractorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sampleImaAdpcm() throws Exception {
|
public void sample_withTrailingBytes_extractsSameData() throws Exception {
|
||||||
|
ExtractorAsserts.assertBehavior(
|
||||||
|
WavExtractor::new,
|
||||||
|
"wav/sample_with_trailing_bytes.wav",
|
||||||
|
ApplicationProvider.getApplicationContext(),
|
||||||
|
/* dumpFilesPrefix= */ "wav/sample.wav");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sample_imaAdpcm() throws Exception {
|
||||||
ExtractorAsserts.assertBehavior(WavExtractor::new, "wav/sample_ima_adpcm.wav");
|
ExtractorAsserts.assertBehavior(WavExtractor::new, "wav/sample_ima_adpcm.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
testdata/src/test/assets/wav/sample_with_trailing_bytes.wav
vendored
Normal file
BIN
testdata/src/test/assets/wav/sample_with_trailing_bytes.wav
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue