Fix Mp4Extractor OutOfBounds exception when sample tables are omitted
When `FLAG_OMIT_TRACK_SAMPLE_TABLE` is set, `Mp4Extractor` initializes per-sample arrays (like `timestampsUs`) with length 0 to save memory, but the total `sampleCount` remains greater than 0. If an MP4 file lacks an `stss` box, all frames are considered sync samples. When scanning for a thumbnail or resolving seek points, the extractor limits its search to the number of sync samples. In this case, that limit becomes the total `sampleCount`. Because the extractor attempts to loop up to `sampleCount` and read from the 0-length `timestampsUs` array, it throws an `ArrayIndexOutOfBoundsException`. This change fixes the issue by adding `hasSampleTableData()` checks to `findBestThumbnailPresentationTimeUs` and `TrackSampleTable` search methods to return early when the per-sample mapping arrays are empty. The test file was generated from the existing `sample.mp4` asset. To ensure it lacks an `stss` box, every video frame was forced to be a keyframe (GOP size 1). The audio track was also removed to reduce file size. `$ ffmpeg -i sample.mp4 -c:v libx264 -g 1 -an sample_without_stss.mp4` PiperOrigin-RevId: 908211794 (cherry picked from commit 802042e3da151a404f8bf7753c3935edc1cff764)
R
rohks committed
a2bc30474e3313e8bc690428d9c8615b99ffc25d
Parent: 2142ab0
Committed by Kim Van Den Eeckhaut <kimvde@google.com>
on 4/30/2026, 4:12:00 PM