Repository navigation
media: apple: avd: validate H.264 slice starts and AV1 tile layouts against the picture - #3197
Conversation
A slice's first_mb_in_slice is programmed as the decoder's macroblock column and row, first_mb_in_slice % PicWidthInMbs and first_mb_in_slice / PicWidthInMbs. Neither the control core nor the driver bounded it: a slice continuing a held picture could start far below a small picture, so the decoder was told a position outside the picture its output and scratch buffers were sized for. H.264 7.4.3 requires first_mb_in_slice * (1 + MbaffFrameFlag) to be less than PicSizeInMbs. Check that in u64 when the slice runs, against the SPS and field flag of the request, and refuse the request with -EINVAL otherwise. The first slice of a held picture also records the picture size, and a later slice of that picture must have the same size, so an SPS change in the middle of a picture cannot move its slices out of it. As for the other refused slices, the held picture is dropped. Add KUnit cases for slices at and past PicSizeInMbs (16 and 16383 on a 64x64 picture, U32_MAX, a picture of 2^32 macroblocks), field and MBAFF pictures, and held pictures of another size, and cases to the production H.264 run fixture in tests/program-test.py: continuation slices at 8160, 16383 and U32_MAX on 1920x1088 and one with another SPS width are refused and drop only the held picture, and one at 8159 is taken. Signed-off-by: Dj <[email protected]>
set_tiles() programs every tile's start and end superblock from the frame's tile_info: mi_col_starts[] and mi_row_starts[] for the start and width_in_sbs_minus_1[] and height_in_sbs_minus_1[] for the size. The work buffers are sized from the same sizes. Only the tile counts and the tile-group indices were checked, so a small frame could carry a tile of 4096x4096 superblocks, and the decoder was told to decode far outside the frame its buffers were sized for. Check the layout the way tile_info() builds it (AV1 5.9.15): per dimension at least one tile and no more than tile_info holds, each tile starting at the superblocks of the tiles before it, and the tile sizes adding up to the frame's superblocks, from MiCols and MiRows of the frame size (AV1 5.9.9) and the sequence's superblock size. The sums are bounded before they are made, so a huge size cannot wrap into place. The CDF update tile must be one of the frame's tiles (AV1 6.8.14). A request that fails is refused with -EINVAL before any tile is programmed. Add KUnit cases for one tile and 2x2 uniform tiles at 1080p, partial superblocks at 66x66 and 128x128 superblocks, and for the 4096x4096 superblock tile on a 64x64 frame, starts and sizes one off, a size that wraps into the next column, no tiles, more tiles than tile_info holds and a CDF tile past the tiles. The production preamble fixture in avd-av1-tail-tests.py now gives its frames one tile covering them, checks that the preamble refuses bad layouts, and runs two new mutations. Signed-off-by: Dj <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Verdict at Blockers: none Checked:
Evidence
|
|
J714s (MacBook Pro 14" M5 Pro, T6050) row at
|
There was a problem hiding this comment.
Verdict: FINISH, then merge at b779e80b
Blockers:
- Merge conflict (
CONFLICTING) againstmain; rebase onto currentmainand re-run CI (3 checks were cancelled atb779e80b).
Checked:
- Verified mergeability (
CONFLICTING) and existingJ714sM5 Pro PASS row atb779e80b. - Deferred final diff approval until the conflict against
mainis resolved and CI finishes green.
Evidence
- Head
b779e80bvsmain:CONFLICTING; CI 20 passed, 3 cancelled.
Forward-merge main. Only the KUnit file avd-h264-test.c conflicted: main added the Annex-B parser and slice header cases and its avd-h264-parse.h include, this branch the slice start and picture size cases and avd-h264-params.h. The file keeps both sets of cases and both includes. Signed-off-by: Ryan Murray <[email protected]>
|
Forward-merged main into this branch (merge commit a19ae97, no force push). Only avd-h264-test.c conflicted. Main added the Annex-B parser and slice-header cases plus the |
There was a problem hiding this comment.
Verdict: MERGE at a19ae973a027
Blockers: None (wait for queued CI to finish green).
Checked:
- Forward merge
a19ae973a027ofmain(MERGEABLE):avd-h264-test.ckeeps bothmain's Annex-B/slice-header tests and this branch'savd_slice_start_test/avd_slice_pic_size_test; driver files are unchanged fromb779e80b. - Full driver audit of
drivers/media/platform/apple/avd/avd-av1.c,avd-h264-params.h,avd-h264.c, andavd.h:avd_av1_check_tile_dim()andavd_av1_check_tile_info(): validates1 <= tiles <= max_tiles,start < sbs, exactmi_starts[i] == start << sb_shift, overflow-safesbs_minus_1[i] < sbs - start, exact frame coveragestart == sbs, andcontext_update_tile_id < tile_cols * tile_rowsbefore programming tile registers or sizing work buffers.avd_h264_pic_size()andavd_h264_slice_in_picture(): computes picture macroblock count inu64respectingFRAME_MBS_ONLY,FIELD_PIC, andMB_ADAPTIVE_FRAME_FIELDper H.264 7.4.2.1.1/7.4.3, validates((u64)first_mb << mbaff) < pic->mbs, and rejects mid-picture size changes across held slices.
- Verification at
a19ae973a027:KUnit avd229/229 pass (includingapple-avd-h264andapple-avd-av1),run-host-tests.py --only avd16/16 pass;J714sM5 Pro hardware row fromb779e80bstands with unchanged driver files.
Evidence
- Verified
avd_h264_run()validatespicbeforeavd_h264_pick_bank()and recordsh264_ctx->b->pic = picon each new frame. - Queued CI checks at
a19ae973a027must finish green before merge.
|
code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at |
|
code-owner ping @DjDeveloperr: closeout merge at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
What: Two decoder geometry checks.
first_mb_in_slicebecame the programmed macroblock position unchecked, so a slice continuing a held picture could start far outside a small picture. It must now be below PicSizeInMbs (H.264 7.4.3), and later slices of a held picture must keep that picture's size.tile_info()lays it out (AV1 5.9.15).Both checks refuse the request with -EINVAL before anything is programmed.
Tested: these pass: the host fixtures
program-test.py(productionavd_h264_run()),av1-test.pyandavd-av1-tail-tests.py(both new mutations are killed), and the AVD KUnit suites on arm64 QEMU (219/219). J700 (Neo) atb779e80bab82, in the combined candidate 7.3.0-neo-combined1126, which carries it unchanged: AV1 3/3 and single-slice H.264 2/2 streams decode exactly as on base (180/180 frames each). Every malformed H.264 continuation and AV1 tile layout is refused by its own check, on a fresh stream per case (4 and 5 refusal lines). 0 DART faults, 0 decoder timeouts. J714s (M5 Pro) atb779e80bab82, in the combined candidate 7.3.0-m5-rows-sec2, which carries it unchanged: H.264 (120 frames) and AV1 (60 frames) decode exactly as on base. 0 DART faults.Risk: two-way · all Macs with AVD H.264 or AV1 decode. A conformant stream passes both checks.
Not yet: the M5 Pro's malformed-input re-run with a fresh stream per case; its decode rows already match base.
Details
H.264 (first commit):
avd_h264_pic_size()gives PicWidthInMbs and PicSizeInMbs in u64, as 7.4.2.1.1 and 7.4.3 define them, including field and MBAFF pictures.avd_h264_run()refuses a slice withfirst_mb_in_slice * (1 + MbaffFrameFlag) >= PicSizeInMbs.AV1 (second commit):
avd_av1_check_tile_info()runs in the run preamble, after the frame size check and before the tile group is read.tile_infoholds. Each tile must start at the superblocks of the tiles before it (<< sbShift, in MI units), and the sizes must add up to the frame's superblocks. Those come from MiCols/MiRows of the frame size (AV1 5.9.9) and the sequence's 64 or 128 superblock size.context_update_tile_idmust name one of the frame's tiles (AV1 6.8.14).avd-av1-tail-tests.pynow gives its frames one tile covering them, and checks the preamble's refusals. Its two new mutations are registered inrun-host-tests.py.Evidence
python3 drivers/media/platform/apple/avd/tests/program-test.py OUT: PASS. Against the unfixedavd-h264.c, the new case fails at the continuation slice at 8160.tools/asahi/run-host-tests.py --only avd: 14/14, including--mutation tile-info-uncheckedand--mutation tile-end-uncheckedkilled.python3 drivers/media/platform/apple/avd/tests/av1-test.py OUT: PASS../tools/testing/kunit/kunit.py run --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/media/platform/apple/avd/tests/.kunitconfig. New:avd_slice_start_test(17 cases),avd_slice_pic_size_test,avd_av1_tile_info_test(23 cases).