Commit ae0d9b13 by ibaker Committed by kim-vde

Preserve limit when resetting ParsableByteArray in OggPacket#populate

When I moved ParsableByteArray#data behind a getter I replaced some
assignments with calls to reset(byte[]):
https://github.com/google/ExoPlayer/commit/ce2e6e2fd625db787b1f400614adcd7458144bbd

reset(byte[]) deliberately sets `limit` to `data.length`, in order to
handle cases that were reassigning `data` but not updating `limit`.
However OggPacket was already using `limit` to track where to write
'new' data into the array, so changing `limit` to `data.length` caused
us to try and write new data beyond the end of the array.

I looked at other uses of reset(byte[]) in https://github.com/google/ExoPlayer/commit/ce2e6e2fd625db787b1f400614adcd7458144bbd
and condluded the only other usage in MatroskaExtractor is legit and
shouldn't be updated like this (because MatroskaExtractor previously
*wasn't* correctly updating/maintaining `limit`).

Issue: #7992
PiperOrigin-RevId: 334601586
parent a0d99a6a
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
([#7967](https://github.com/google/ExoPlayer/issues/7967)). ([#7967](https://github.com/google/ExoPlayer/issues/7967)).
* Use TLEN ID3 tag to compute the duration in Mp3Extractor * Use TLEN ID3 tag to compute the duration in Mp3Extractor
([#7949](https://github.com/google/ExoPlayer/issues/7949)). ([#7949](https://github.com/google/ExoPlayer/issues/7949)).
* Fix regression for Ogg files with packets that span multiple pages
([#7992](https://github.com/google/ExoPlayer/issues/7992)).
* UI * UI
* Add the option to sort tracks by `Format` in `TrackSelectionView` and * Add the option to sort tracks by `Format` in `TrackSelectionView` and
`TrackSelectionDialogBuilder` `TrackSelectionDialogBuilder`
......
...@@ -88,7 +88,9 @@ import java.util.Arrays; ...@@ -88,7 +88,9 @@ import java.util.Arrays;
int segmentIndex = currentSegmentIndex + segmentCount; int segmentIndex = currentSegmentIndex + segmentCount;
if (size > 0) { if (size > 0) {
if (packetArray.capacity() < packetArray.limit() + size) { if (packetArray.capacity() < packetArray.limit() + size) {
packetArray.reset(Arrays.copyOf(packetArray.getData(), packetArray.limit() + size)); packetArray.reset(
Arrays.copyOf(packetArray.getData(), packetArray.limit() + size),
/* limit= */ packetArray.limit());
} }
input.readFully(packetArray.getData(), packetArray.limit(), size); input.readFully(packetArray.getData(), packetArray.limit(), size);
packetArray.setLimit(packetArray.limit() + size); packetArray.setLimit(packetArray.limit() + size);
...@@ -131,7 +133,8 @@ import java.util.Arrays; ...@@ -131,7 +133,8 @@ import java.util.Arrays;
} }
packetArray.reset( packetArray.reset(
Arrays.copyOf( Arrays.copyOf(
packetArray.getData(), max(OggPageHeader.MAX_PAGE_PAYLOAD, packetArray.limit()))); packetArray.getData(), max(OggPageHeader.MAX_PAGE_PAYLOAD, packetArray.limit())),
/* limit= */ packetArray.limit());
} }
/** /**
......
...@@ -60,11 +60,27 @@ public final class OggExtractorParameterizedTest { ...@@ -60,11 +60,27 @@ public final class OggExtractorParameterizedTest {
OggExtractor::new, "media/ogg/bear_vorbis.ogg", simulationConfig); OggExtractor::new, "media/ogg/bear_vorbis.ogg", simulationConfig);
} }
// Ensure the extractor can handle non-contiguous pages by using a file with 10 bytes of garbage /**
// data before the start of the second page. * Ensure the extractor can handle non-contiguous pages by using a file with 10 bytes of garbage
* data before the start of the second page.
*
* <p>https://github.com/google/ExoPlayer/issues/7230
*/
@Test @Test
public void vorbisWithGapBeforeSecondPage() throws Exception { public void vorbisWithGapBeforeSecondPage() throws Exception {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
OggExtractor::new, "media/ogg/bear_vorbis_gap.ogg", simulationConfig); OggExtractor::new, "media/ogg/bear_vorbis_gap.ogg", simulationConfig);
} }
/**
* Use some very large Vorbis Comment metadata to create a packet that is larger than a single Ogg
* page.
*
* <p>https://github.com/google/ExoPlayer/issues/7992
*/
@Test
public void vorbisWithPacketSpanningBetweenPages() throws Exception {
ExtractorAsserts.assertBehavior(
OggExtractor::new, "media/ogg/bear_vorbis_with_large_metadata.ogg", simulationConfig);
}
} }
seekMap:
isSeekable = true
duration = 2741000
getPosition(0) = [[timeUs=0, position=84969]]
getPosition(1) = [[timeUs=1, position=84969]]
getPosition(1370500) = [[timeUs=1370500, position=84969]]
getPosition(2741000) = [[timeUs=2741000, position=84969]]
numberOfTracks = 1
track 0:
total output bytes = 17598
sample count = 109
format 0:
averageBitrate = 112000
sampleMimeType = audio/vorbis
channelCount = 2
sampleRate = 48000
initializationData:
data = length 30, hash 9A8FF207
data = length 3832, hash 8A406249
sample 0:
time = 905333
flags = 1
data = length 195, hash 2722159A
sample 1:
time = 926666
flags = 1
data = length 199, hash 10CEE97A
sample 2:
time = 948000
flags = 1
data = length 191, hash 2CF9FB3F
sample 3:
time = 969333
flags = 1
data = length 197, hash A725DA0
sample 4:
time = 990666
flags = 1
data = length 211, hash D4E5DB9E
sample 5:
time = 1012000
flags = 1
data = length 189, hash 1A90F496
sample 6:
time = 1033333
flags = 1
data = length 187, hash 44DB2689
sample 7:
time = 1054666
flags = 1
data = length 197, hash 6D3E5117
sample 8:
time = 1076000
flags = 1
data = length 208, hash 5B57B288
sample 9:
time = 1097333
flags = 1
data = length 198, hash D5FC05
sample 10:
time = 1118666
flags = 1
data = length 192, hash 350BBA45
sample 11:
time = 1140000
flags = 1
data = length 195, hash 5F96F2A8
sample 12:
time = 1161333
flags = 1
data = length 202, hash 61D7CC33
sample 13:
time = 1182666
flags = 1
data = length 202, hash 49D335F2
sample 14:
time = 1204000
flags = 1
data = length 192, hash 2FE9CB1A
sample 15:
time = 1225333
flags = 1
data = length 201, hash BF0763B2
sample 16:
time = 1246666
flags = 1
data = length 184, hash AD047421
sample 17:
time = 1268000
flags = 1
data = length 196, hash F9088F14
sample 18:
time = 1289333
flags = 1
data = length 190, hash AC6D38FD
sample 19:
time = 1310666
flags = 1
data = length 195, hash 8D1A66D2
sample 20:
time = 1332000
flags = 1
data = length 197, hash B46BFB6B
sample 21:
time = 1353333
flags = 1
data = length 195, hash D9761F23
sample 22:
time = 1374666
flags = 1
data = length 204, hash 3391B617
sample 23:
time = 1396000
flags = 1
data = length 42, hash 33A1FB52
sample 24:
time = 1408000
flags = 1
data = length 44, hash 408B146E
sample 25:
time = 1410666
flags = 1
data = length 44, hash 171C7E0D
sample 26:
time = 1413333
flags = 1
data = length 54, hash 6307E16C
sample 27:
time = 1416000
flags = 1
data = length 53, hash 4A319572
sample 28:
time = 1418666
flags = 1
data = length 215, hash BA9C445C
sample 29:
time = 1430666
flags = 1
data = length 201, hash 3120D234
sample 30:
time = 1452000
flags = 1
data = length 187, hash DB44993C
sample 31:
time = 1473333
flags = 1
data = length 196, hash CF2002D7
sample 32:
time = 1494666
flags = 1
data = length 185, hash E03B5D7
sample 33:
time = 1516000
flags = 1
data = length 187, hash DA399A2C
sample 34:
time = 1537333
flags = 1
data = length 191, hash 292AA0DB
sample 35:
time = 1558666
flags = 1
data = length 201, hash 221910E0
sample 36:
time = 1580000
flags = 1
data = length 194, hash F4ED7821
sample 37:
time = 1601333
flags = 1
data = length 43, hash FDDA515E
sample 38:
time = 1613333
flags = 1
data = length 42, hash F3571C0A
sample 39:
time = 1616000
flags = 1
data = length 38, hash 39F910B3
sample 40:
time = 1618666
flags = 1
data = length 41, hash 2D189531
sample 41:
time = 1621333
flags = 1
data = length 43, hash 1F7574DB
sample 42:
time = 1624000
flags = 1
data = length 43, hash 644D15E5
sample 43:
time = 1626666
flags = 1
data = length 49, hash E8A0878
sample 44:
time = 1629333
flags = 1
data = length 55, hash DFF2046D
sample 45:
time = 1632000
flags = 1
data = length 49, hash 9FB8A23
sample 46:
time = 1634666
flags = 1
data = length 41, hash E3E15E3B
sample 47:
time = 1637333
flags = 1
data = length 42, hash E5D17A32
sample 48:
time = 1640000
flags = 1
data = length 42, hash F308B653
sample 49:
time = 1642666
flags = 1
data = length 55, hash BB750D76
sample 50:
time = 1645333
flags = 1
data = length 51, hash 96772ABF
sample 51:
time = 1648000
flags = 1
data = length 197, hash E4524346
sample 52:
time = 1660000
flags = 1
data = length 188, hash AC3E1BB5
sample 53:
time = 1681333
flags = 1
data = length 195, hash F56DB8A5
sample 54:
time = 1702666
flags = 1
data = length 198, hash C8970FF7
sample 55:
time = 1724000
flags = 1
data = length 202, hash AF425C68
sample 56:
time = 1745333
flags = 1
data = length 196, hash 4215D839
sample 57:
time = 1766666
flags = 1
data = length 204, hash DB9BE8E3
sample 58:
time = 1788000
flags = 1
data = length 206, hash E5B20AB8
sample 59:
time = 1809333
flags = 1
data = length 209, hash D7F47B95
sample 60:
time = 1830666
flags = 1
data = length 193, hash FB54FB05
sample 61:
time = 1852000
flags = 1
data = length 199, hash D99C3106
sample 62:
time = 1873333
flags = 1
data = length 206, hash 253885B9
sample 63:
time = 1894666
flags = 1
data = length 191, hash FBDD8162
sample 64:
time = 1916000
flags = 1
data = length 183, hash 7290332F
sample 65:
time = 1937333
flags = 1
data = length 189, hash 1A9DC3DE
sample 66:
time = 1958666
flags = 1
data = length 201, hash 5D936764
sample 67:
time = 1980000
flags = 1
data = length 193, hash 6B03E75E
sample 68:
time = 2001333
flags = 1
data = length 199, hash 8A21BA83
sample 69:
time = 2022666
flags = 1
data = length 41, hash E6362210
sample 70:
time = 2034666
flags = 1
data = length 43, hash 36A57B44
sample 71:
time = 2037333
flags = 1
data = length 43, hash E51797D5
sample 72:
time = 2040000
flags = 1
data = length 43, hash 1F336C72
sample 73:
time = 2042666
flags = 1
data = length 42, hash 201AD367
sample 74:
time = 2045333
flags = 1
data = length 50, hash 606CCD6
sample 75:
time = 2048000
flags = 1
data = length 56, hash B15EBD7A
sample 76:
time = 2050666
flags = 1
data = length 212, hash 273B8D22
sample 77:
time = 2062666
flags = 1
data = length 194, hash 44F9CE1
sample 78:
time = 2084000
flags = 1
data = length 195, hash EDF9EBA1
sample 79:
time = 2105333
flags = 1
data = length 194, hash CE9F2D26
sample 80:
time = 2126666
flags = 1
data = length 192, hash 204F8A23
sample 81:
time = 2148000
flags = 1
data = length 206, hash DFA57E67
sample 82:
time = 2169333
flags = 1
data = length 196, hash 3CF084AB
sample 83:
time = 2190666
flags = 1
data = length 202, hash 2AF75C08
sample 84:
time = 2212000
flags = 1
data = length 203, hash 748EAF7
sample 85:
time = 2233333
flags = 1
data = length 205, hash ED82379D
sample 86:
time = 2254666
flags = 1
data = length 193, hash 61F26F22
sample 87:
time = 2276000
flags = 1
data = length 189, hash 85EF1D20
sample 88:
time = 2297333
flags = 1
data = length 187, hash 25E41FBF
sample 89:
time = 2318666
flags = 1
data = length 199, hash F365808
sample 90:
time = 2340000
flags = 1
data = length 197, hash 94205329
sample 91:
time = 2361333
flags = 1
data = length 201, hash FA2B2055
sample 92:
time = 2382666
flags = 1
data = length 194, hash AF95381F
sample 93:
time = 2404000
flags = 1
data = length 201, hash 923D3534
sample 94:
time = 2425333
flags = 1
data = length 198, hash 35F84C2E
sample 95:
time = 2446666
flags = 1
data = length 204, hash 6642CA40
sample 96:
time = 2468000
flags = 1
data = length 183, hash 3E2DC6BE
sample 97:
time = 2489333
flags = 1
data = length 197, hash B1E458CE
sample 98:
time = 2510666
flags = 1
data = length 193, hash E9218C84
sample 99:
time = 2532000
flags = 1
data = length 192, hash FEF08D4B
sample 100:
time = 2553333
flags = 1
data = length 201, hash FC411147
sample 101:
time = 2574666
flags = 1
data = length 218, hash 86893464
sample 102:
time = 2596000
flags = 1
data = length 226, hash 31C5320
sample 103:
time = 2617333
flags = 1
data = length 233, hash 9432BEE5
sample 104:
time = 2638666
flags = 1
data = length 213, hash B3FCC53E
sample 105:
time = 2660000
flags = 1
data = length 204, hash D70DD5A2
sample 106:
time = 2681333
flags = 1
data = length 212, hash A4EF1B69
sample 107:
time = 2702666
flags = 1
data = length 203, hash 8B0748B5
sample 108:
time = 2724000
flags = 1
data = length 149, hash E455335B
tracksEnded = true
seekMap:
isSeekable = true
duration = 2741000
getPosition(0) = [[timeUs=0, position=84969]]
getPosition(1) = [[timeUs=1, position=84969]]
getPosition(1370500) = [[timeUs=1370500, position=84969]]
getPosition(2741000) = [[timeUs=2741000, position=84969]]
numberOfTracks = 1
track 0:
total output bytes = 8658
sample count = 49
format 0:
averageBitrate = 112000
sampleMimeType = audio/vorbis
channelCount = 2
sampleRate = 48000
initializationData:
data = length 30, hash 9A8FF207
data = length 3832, hash 8A406249
sample 0:
time = 1821333
flags = 1
data = length 193, hash FB54FB05
sample 1:
time = 1842666
flags = 1
data = length 199, hash D99C3106
sample 2:
time = 1864000
flags = 1
data = length 206, hash 253885B9
sample 3:
time = 1885333
flags = 1
data = length 191, hash FBDD8162
sample 4:
time = 1906666
flags = 1
data = length 183, hash 7290332F
sample 5:
time = 1928000
flags = 1
data = length 189, hash 1A9DC3DE
sample 6:
time = 1949333
flags = 1
data = length 201, hash 5D936764
sample 7:
time = 1970666
flags = 1
data = length 193, hash 6B03E75E
sample 8:
time = 1992000
flags = 1
data = length 199, hash 8A21BA83
sample 9:
time = 2013333
flags = 1
data = length 41, hash E6362210
sample 10:
time = 2025333
flags = 1
data = length 43, hash 36A57B44
sample 11:
time = 2028000
flags = 1
data = length 43, hash E51797D5
sample 12:
time = 2030666
flags = 1
data = length 43, hash 1F336C72
sample 13:
time = 2033333
flags = 1
data = length 42, hash 201AD367
sample 14:
time = 2036000
flags = 1
data = length 50, hash 606CCD6
sample 15:
time = 2038666
flags = 1
data = length 56, hash B15EBD7A
sample 16:
time = 2041333
flags = 1
data = length 212, hash 273B8D22
sample 17:
time = 2053333
flags = 1
data = length 194, hash 44F9CE1
sample 18:
time = 2074666
flags = 1
data = length 195, hash EDF9EBA1
sample 19:
time = 2096000
flags = 1
data = length 194, hash CE9F2D26
sample 20:
time = 2117333
flags = 1
data = length 192, hash 204F8A23
sample 21:
time = 2138666
flags = 1
data = length 206, hash DFA57E67
sample 22:
time = 2160000
flags = 1
data = length 196, hash 3CF084AB
sample 23:
time = 2181333
flags = 1
data = length 202, hash 2AF75C08
sample 24:
time = 2202666
flags = 1
data = length 203, hash 748EAF7
sample 25:
time = 2224000
flags = 1
data = length 205, hash ED82379D
sample 26:
time = 2245333
flags = 1
data = length 193, hash 61F26F22
sample 27:
time = 2266666
flags = 1
data = length 189, hash 85EF1D20
sample 28:
time = 2288000
flags = 1
data = length 187, hash 25E41FBF
sample 29:
time = 2309333
flags = 1
data = length 199, hash F365808
sample 30:
time = 2330666
flags = 1
data = length 197, hash 94205329
sample 31:
time = 2352000
flags = 1
data = length 201, hash FA2B2055
sample 32:
time = 2373333
flags = 1
data = length 194, hash AF95381F
sample 33:
time = 2394666
flags = 1
data = length 201, hash 923D3534
sample 34:
time = 2416000
flags = 1
data = length 198, hash 35F84C2E
sample 35:
time = 2437333
flags = 1
data = length 204, hash 6642CA40
sample 36:
time = 2458666
flags = 1
data = length 183, hash 3E2DC6BE
sample 37:
time = 2480000
flags = 1
data = length 197, hash B1E458CE
sample 38:
time = 2501333
flags = 1
data = length 193, hash E9218C84
sample 39:
time = 2522666
flags = 1
data = length 192, hash FEF08D4B
sample 40:
time = 2544000
flags = 1
data = length 201, hash FC411147
sample 41:
time = 2565333
flags = 1
data = length 218, hash 86893464
sample 42:
time = 2586666
flags = 1
data = length 226, hash 31C5320
sample 43:
time = 2608000
flags = 1
data = length 233, hash 9432BEE5
sample 44:
time = 2629333
flags = 1
data = length 213, hash B3FCC53E
sample 45:
time = 2650666
flags = 1
data = length 204, hash D70DD5A2
sample 46:
time = 2672000
flags = 1
data = length 212, hash A4EF1B69
sample 47:
time = 2693333
flags = 1
data = length 203, hash 8B0748B5
sample 48:
time = 2714666
flags = 1
data = length 149, hash E455335B
tracksEnded = true
seekMap:
isSeekable = true
duration = 2741000
getPosition(0) = [[timeUs=0, position=84969]]
getPosition(1) = [[timeUs=1, position=84969]]
getPosition(1370500) = [[timeUs=1370500, position=84969]]
getPosition(2741000) = [[timeUs=2741000, position=84969]]
numberOfTracks = 1
track 0:
total output bytes = 0
sample count = 0
format 0:
averageBitrate = 112000
sampleMimeType = audio/vorbis
channelCount = 2
sampleRate = 48000
initializationData:
data = length 30, hash 9A8FF207
data = length 3832, hash 8A406249
tracksEnded = true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment