Skip to content

Fix heap over-read of truncated display-matrix side-data in FFmpegAssetTrack - #930

Open
YuriNachos wants to merge 1 commit into
kingslay:mainfrom
YuriNachos:YuriNachos/w3-ksplayer-displaymatrix
Open

YuriNachos wants to merge 1 commit into
kingslay:mainfrom
YuriNachos:YuriNachos/w3-ksplayer-displaymatrix

Conversation

@YuriNachos

Copy link
Copy Markdown
Contributor

av_display_rotation_get dereferences a 3×3 matrix of 9 × Int32 (36 bytes) unconditionally, but the AV_PKT_DATA_DISPLAYMATRIX side-data branch read it with no length check. FFmpeg emits exactly 36 bytes for a well-formed display matrix, but a malformed/cropped container can hand us a shorter allocation, so the read over-runs into adjacent heap. PR #908 hardened only the rotation result (isFinite), not the read itself — the over-read still happens before isFinite is evaluated.

Fix

Extract a displayRotation(sideDataSize:matrix:) helper that returns nil unless sideDataSize >= 9 * MemoryLayout<Int32>.size, and continue past the side-data when it does. The track still initialises and rotation keeps its default 0; behaviour is unchanged for well-formed streams. Different file/line from #928 (audio nominalFrameRate) and the open #927 (FFmpegDecode.swift).

Test plan

swift test — 13 passed, 0 failed, including a new DisplayMatrixRotationTest covering size == 36 (identity matrix → rotation 0; 90° matrix → finite, in range) and size < 36 (truncated → no read / nil). No signing/device needed.

…etTrack

av_display_rotation_get dereferences a 3x3 matrix of 9 x Int32 (36 bytes)
unconditionally, but the AV_PKT_DATA_DISPLAYMATRIX side-data branch read it
with no sideData.size check. FFmpeg normally allocates exactly 36 bytes, but a
malformed/cropped MKV or MP4 can attach a shorter allocation, over-reading
adjacent heap. PR kingslay#908 hardened only the rotation result (isFinite), not the
read length.

Guard the length before the read via a testable
displayRotation(sideDataSize:matrix:) helper that returns nil unless
sideDataSize >= 9 * MemoryLayout<Int32>.size, and continue past the side-data
when it does. The track still initialises and rotation keeps its default 0;
the existing isFinite NaN path is untouched, so well-formed streams are
unchanged. Adds DisplayMatrixRotationTest covering size 36 (identity -> 0,
90deg matrix -> +90) and size 35 / 0 (nil, no read).
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.

1 participant