picture: bounds-check codec_store_buffer slice writes against source_size (#13) #14
Reference in New Issue
Block a user
Delete Branch "claude-noether/libva-v4l2-request-fourier:noether/codec-store-buffer-bounds-check-13"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the unbounded
memcpys incodec_store_buffer'sVASliceDataBufferTypebranch reported in #13.What changes
Three append sites in
src/picture.cnow checkslices_size + needed <= source_sizebefore writing:buffer_object->size * buffer_object->count)If any check fails,
RenderPicturereturnsVA_STATUS_ERROR_ALLOCATION_FAILEDandrequest_logrecords the over-budget request. Theslices_size/slices_countstate is left consistent (we only advance after the successful copy), so the surface is recoverable; libavcodec re-creates the surface at the new resolution on the nextBeginPicture.Why this is sufficient (and why it's only the floor)
source_datais the mmap of an OUTPUT pool slot whose size is set byv4l2_query_bufferatrequest_pool_inittime — i.e. the kernel driver's negotiatedsizeimagefromS_FMT. That number is fixed for the life of the pool, so an SPS-driven resolution upshift mid-stream that produces a slice larger than the pool slot'ssizeimagewill overflow.Issue #13 also suggests a better-fix track: re-create surfaces (and re-
S_FMT/ re-init the OUTPUT pool) on resolution change, or growsource_dataon demand. Both are larger refactors; this PR is the memory-safety floor that should land first.Notes on the C scoping
Wrapped the
case VASliceDataBufferType:body in a{ ... }block to allow declaringsize_t cap = surface_object->source_size;andsize_t need;at the top of the case without C90 declaration-after-statement noise. No behavioural change for the othercasearms.Test plan
libva-v4l2-request-fourier-aarch64+-debianjobs).mpv --hwdec=vaapi-copy bbb_1080p30_h264.mp4against a 720p-default daedalus session no longer SIGSEGVs inmemcpy, and instead surfaces a cleanVA_STATUS_ERROR_ALLOCATION_FAILEDto libavcodec;request_logshows thewould overflow OUTPUT bufferline with the over-budget delta.slices_size + payload <= source_sizeshould hold trivially for any session that wasn't already on the verge of corruption.