Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException due to invalid colr atom #9332

Closed
liulei9385 opened this issue Aug 25, 2021 · 15 comments
Closed

ArrayIndexOutOfBoundsException due to invalid colr atom #9332

liulei9385 opened this issue Aug 25, 2021 · 15 comments

Comments

@liulei9385
Copy link

liulei9385 commented Aug 25, 2021

I'm play a simple mp4 file and cause those error below:

2021-08-25 14:13:23.644 com.aoaojao.app.global E/EventLogger: playerFailed [eventTime=3228.55, mediaPos=0.00, window=10, period=10, errorCode=ERROR_CODE_IO_UNSPECIFIED
      com.google.android.exoplayer2.ExoPlaybackException: Source error
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:624)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:600)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:154)
        at android.os.HandlerThread.run(HandlerThread.java:61)
     Caused by: com.google.android.exoplayer2.upstream.Loader$UnexpectedLoaderException: Unexpected ArrayIndexOutOfBoundsException: length=162; index=162
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:430)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:761)
     Caused by: java.lang.ArrayIndexOutOfBoundsException: length=162; index=162
        at com.google.android.exoplayer2.util.ParsableByteArray.readUnsignedByte(ParsableByteArray.java:233)
        at com.google.android.exoplayer2.extractor.mp4.AtomParsers.parseVideoSampleEntry(AtomParsers.java:1203)
        at com.google.android.exoplayer2.extractor.mp4.AtomParsers.parseStsd(AtomParsers.java:949)
        at com.google.android.exoplayer2.extractor.mp4.AtomParsers.parseTrak(AtomParsers.java:308)
        at com.google.android.exoplayer2.extractor.mp4.AtomParsers.parseTraks(AtomParsers.java:130)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.processMoovAtom(Mp4Extractor.java:483)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.processAtomEnded(Mp4Extractor.java:442)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readAtomPayload(Mp4Extractor.java:424)
        at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:242)
        at com.google.android.exoplayer2.source.BundledExtractorsAdapter.read(BundledExtractorsAdapter.java:127)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1047)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:409)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
        at java.lang.Thread.run(Thread.java:761) 
    ]

I debug the AtomParsers.java the line 1203 method cause the problem.
1629871704(1)

when I change parent data's position that make method pass then I can play video successfully.
Is there any good way to avoid mistakes

This is my video test link.
the video link

My exoplayer2 version is 2.15.0

@icbaker
Copy link
Collaborator

icbaker commented Aug 25, 2021

I can play the attached video successfully on 2.14.2 and it crashes with the same stack trace on 2.15.0 so I agree this looks like a regression.

@kim-vde can you take a look?

@icbaker icbaker assigned kim-vde and unassigned icbaker Aug 25, 2021
@icbaker
Copy link
Collaborator

icbaker commented Aug 25, 2021

Also @AquilesCanta FYI as the author of ddc047c where this stack trace seems to originate.

@AquilesCanta
Copy link
Contributor

Is it also worth branching a github issue or internal bug for the correct assignment of an error code (instead of ERROR_CODE_IO_UNSPECIFIED)?

@icbaker
Copy link
Collaborator

icbaker commented Aug 26, 2021

@AquilesCanta Filed [internal b/197832624].

@icbaker icbaker assigned icbaker and unassigned kim-vde Aug 31, 2021
@icbaker
Copy link
Collaborator

icbaker commented Aug 31, 2021

The video file provided has an invalid colr box. Its size is reported as 18 bytes, but it has color_type=nclx which, according to section 8.5.2.2 of ISO/IEC 14496-12:2012(E) means the expected box size is 19 bytes (8 bytes for size & type, then 11 bytes for the colr box content).

The 162 in the stack trace comes from the ancestor stsd box which has a size of 162 bytes.

The nclc box defined by Apple is only expected to be 18 bytes, so this looks like a valid example of one of those - but it has color_type=nclx, not nclc.

How did you produce this file? The metadata suggests it might have come from ffmpeg? If so I think you should report this to them.

@liulei9385
Copy link
Author

I don’t know what conversion was done to this video, because it's upload from other mobile phones

@icbaker
Copy link
Collaborator

icbaker commented Sep 1, 2021

Since this is the only example we've seen so far of a file broken in this way I'm going to close this as working-as-intended.

If we see a significant number of files that are invalid in the same way then we'll consider adding a workaround to ExoPlayer to handle this broken-ness more gracefully, but until then we're going to stick to implementing the spec as it's defined.

@onexuan
Copy link

onexuan commented Oct 23, 2021

I can play my local video successfully on 2.14.2 but it crashes on 2.15.0, please fix it
my local video can be played by other players

@ojw28
Copy link
Contributor

ojw28 commented Oct 24, 2021

@onexuan - It sounds like you're seeing this when playing video recorded with your device camera. What device are you using? Please could you also send a sample video to dev.exoplayer@gmail.com.

Reopening this issue because it sounds like the bad media can be generated on device (on at least one device).

@onexuan
Copy link

onexuan commented Oct 25, 2021

Please check your email @ojw28

@icbaker
Copy link
Collaborator

icbaker commented Oct 25, 2021

@onexuan We haven't received your email. Please either upload the media here or send to dev.exoplayer@gmail.com using a subject in the format Issue #1234 (where #1234 should be replaced with this issue number.) Please also update this issue to indicate you’ve done this.

@icbaker icbaker changed the title exoPlayer 2.15.0 cause java.lang.ArrayIndexOutOfBoundsException: length=162; index=162 ArrayIndexOutOfBoundsException due to invalid colr atom Oct 25, 2021
@onexuan
Copy link

onexuan commented Oct 26, 2021

Please check it again

@icbaker
Copy link
Collaborator

icbaker commented Oct 26, 2021

Thanks, I found the media (both the emails you sent were bounced back to you because you didn't use the requested subject line).

The media has the same symptoms as the original video in this issue: an 18 byte colr box with colour_type=nclx

@icbaker
Copy link
Collaborator

icbaker commented Oct 26, 2021

I will modify ExoPlayer to handle files with this combination.

@onexuan
Copy link

onexuan commented Oct 27, 2021

I will modify ExoPlayer to handle files with this combination.

OK, I will test it after the new version is released

marcbaechinger pushed a commit that referenced this issue Oct 27, 2021
Test file produced with:
$ MP4Box -add "sample.mp4#video:colr=nclc,1,1,1" -new sample_18byte_nclx_colr.mp4

And then manually changing the `nclc` bytes to `nclx`.

This produces an 18-byte `colr` box with type `nclx`. The bitstream of
this file does not contain HDR content, so the file itself is invalid
for playback with a real decoder, but adding the box is enough to test
the extractor change in this commit.

(aside: MP4Box will let you pass `nclx`, but it requires 4 parameters, i.e. it
requires the full_range_flag to be set, resulting in a valid 19-byte colr box)

#minor-release
Issue: #9332
PiperOrigin-RevId: 405842520
@icbaker icbaker closed this as completed Oct 28, 2021
@google google locked and limited conversation to collaborators Dec 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants