Skip to content

Fix crash in KSPlayer when reading video rotation from FFmpeg display matrix metadata. - #908

Merged
kingslay merged 1 commit into
kingslay:mainfrom
IgorFedorchuk:fix_infinity_crash
May 15, 2026
Merged

Fix crash in KSPlayer when reading video rotation from FFmpeg display matrix metadata.#908
kingslay merged 1 commit into
kingslay:mainfrom
IgorFedorchuk:fix_infinity_crash

Conversation

@IgorFedorchuk

Copy link
Copy Markdown

Problem
In FFmpegAssetTrack, rotation is parsed from AV_PKT_DATA_DISPLAYMATRIX and converted directly to Int:

rotation = Int16(Int(-av_display_rotation_get(matrix)) % 360)
For some streams, av_display_rotation_get(matrix) returns non-finite values (NaN / Infinity), which causes a runtime fatal error on Int(...) conversion:

Fatal error: Double value cannot be converted to Int because it is either infinite or NaN

Root Cause
No validation of Double finiteness before integer conversion.

Fix
Validate rotation value with isFinite before converting to Int.
Normalize finite values to [0, 359].
Fallback to 0 for invalid values.
Why this change
Prevents hard crash on malformed/invalid display matrix metadata and makes playback startup more robust for edge-case streams.

Impact
✅ Eliminates this crash path during media open.
✅ Keeps valid rotation behavior intact.
✅ Safe fallback for corrupted metadata.
Repro (before fix)
Open a stream/file containing invalid display matrix rotation metadata.
Player reaches FFmpegAssetTrack display matrix parsing.
App crashes with fatal Double -> Int conversion error.
Behavior after fix
Same stream opens without crash; rotation defaults safely when metadata is invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants