0
Fork 0
mirror of https://github.com/Droid-VM/crosvm.git synced 2026-11-17 06:58:03 +00:00
crosvm/android_codec/src/image.rs
HuJK b60d066aa4 android_codec: release_output ends the output borrow, and a bottom-up layout is refused, not indexed
Two review-m6 findings in the crate (logs/vpu_wp/review-m6.md).

R6-13 (nit): Codec::output_buffer returned a slice borrowed from &self while
release_output also took &self, so `let src = codec.output_buffer(i)?;
codec.release_output(i)?; use(src)` compiled: a use after release
expressible with no unsafe. release_output now takes &mut self, which ends
every output_buffer borrow at the release by construction; the two callers
in devices (pump_output, take_output) and codec_probe already hold the
codec mutably, and are adjusted here only where the signature requires it.

R6-9 (minor): MediaImage2::plane_end clamps a negative increment out of its
sum, so check_bounds looked at the first row only of a bottom-up image-data
layout (which the format allows) and tight_nv12_rows then computed a row
start below zero, cast it to usize and panicked on the index -- in the
media helper, i.e. the VM down -- where the function's contract is that
nothing is emitted for a refused layout. A plane_start companion finds the
lowest byte a plane reaches, and check_bounds refuses a layout that reaches
before the buffer with the new ImageError::BelowStart. A bottom-up layout
whose offsets account for the walk is still walked, rows in the order the
picture has them. Not observed on 5566 (B5 §5.2: every rowInc positive); the
codec controls the value, not the guest.

Test: a_bottom_up_layout_is_walked_or_refused_never_indexed_below_zero (31
passed in deploy/vpu/harness.sh acc).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BkN7vYhuc1w9iVuqsHzSn
2026-10-28 06:23:29 +08:00

776 lines
28 KiB