Repository navigation
main, pipewire-frame: check the output frame geometry before writing it - #22
Conversation
The output format took any even NV12 size. Its stride and the requested buffer size were then computed in int, and every frame was checked with `od->maxsize < (uint32_t)c->out_stride * h * 3 / 2`, which wraps modulo 2^32. A 65522x43692 format needs 2^32 + 131072 output bytes, but the check saw 131072, so a 128 KiB buffer passed and the row copies wrote far past it. Add cdn_output_layout(), which computes the stride (the width rounded up to 16) and the NV12 size in 64 bits. It refuses zero or odd sizes, sizes above CDN_MAX_FRAME_DIM (8192, the GPU backend's existing limit, now named in backend.h) and anything that does not fit PipeWire's 32-bit Int. Format negotiation uses it, so such a format is refused before any buffer or backend is set up, and the buffer size comes from it. Add cdn_output_frame(), which maps the output frame onto the buffer only if its mapping holds the whole frame, computed in 64 bits. The process callback uses it before anything is written, and chunk sizes come from the negotiated layout. tests/test_buffers.c checks the layout at its edges and with INT_MAX, UINT32_MAX, a stride that wraps when rounded and the 65522x43692 case, and the output mapping one byte short, missing or too small for the wrapping frame. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Verdict at Blockers: none Checked
Not a blocker: the ANE and AVE plugins write Evidence
|
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
Verdict: MERGE at e75dea3 after the remaining hardware validation.
Checked: negotiation uses a bounded 64-bit layout before narrowing to PipeWire fields, the frame path checks the full NV12 mapping before writing, and chunk size uses the negotiated value. The author and independent sanitizer results cover the layout helpers. The J700 receipt covers landscape and portrait stride. The M5 Pro camera-denoise row remains due.
|
Hardware row at exact head
Trace: |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict at e75dea33fc00: APPROVE (Core non-author review).
Blockers: none.
Checked:
cdn_output_layout()/cdn_output_frame()compute stride and NV12 output size inuint64_t, enforceCDN_MAX_FRAME_DIM(8192) andINT32_MAXbounds at negotiation, and verifymaxsizeholds the full frame before any write.- 10/10 ARM64 F44 Meson tests pass (
buffers,formats, etc.) alongsideaurora-silicon-reviewapproval and CI green. - Verified across both affected platforms: author's
J700(Neo) 1920x1080 + 1080x1920 row and ourK114s(M5 Pro) 1920x1080@30 + 1920x1080@15 live ISP/PipeWire row.
|
Merged at |
What: The output frame's size was computed in 32-bit arithmetic that wraps. A huge NV12 format, 65522x43692, needs 2^32 + 131072 bytes but passed the per-frame check with a 128 KiB buffer, and the row copies then wrote past it. The output geometry is now computed in 64 bits. Formats above the backends' largest frame or PipeWire's 32-bit sizes are refused at negotiation, and the output mapping must hold the whole frame before anything is written.
Tested:
tests/test_buffers.candtests/test_formats.cpass under ASan and UBSan. The daemon compiles warning-free with PipeWire 1.6.11. J700 (Neo) ate75dea33fc00, the real user service with the camera: 1920x1080 (170 frames) and 1080x1920 (88 frames, stride rounded to 1088) negotiate the same size, stride and buffer size as base, with no service errors.Risk: two-way · Neo and M5 Pro, where the camera service runs. Real camera formats are far below the new 8192 limit, so their negotiation and buffers are unchanged.
Not yet: a camera row on the M5 Pro.
Details
cdn_output_layout()computes the stride (width rounded up to 16) and the NV12 size inuint64_t. It refuses zero or odd sizes, sizes aboveCDN_MAX_FRAME_DIM, and a stride or size aboveINT32_MAX, sinceSPA_PARAM_BUFFERS_sizeandstrideare Ints.CDN_MAX_FRAME_DIM(8192) is the GPU backend's existing limit, now named inbackend.hand used there too.on_out_param_changed()refuses such a format withpw_stream_set_error()before buffers or a backend are set up, and takes the buffer size and stride from the layout.cdn_output_frame()maps the output frame onto the first data plane only ifmaxsizeholdsstride * height * 3 / 2, computed in 64 bits.on_in_process()calls it before any write, and the chunk size is the negotiated size.cdn_frame_from_buffer()).Evidence
cc -fsanitize=address,undefined tests/test_buffers.c src/pipewire-frame.c $(pkg-config --cflags --libs libpipewire-0.3): exit 0. It covers layout edges (18x18, 1920x1080, 8192x8192); 8194 refused; zero and odd sizes;INT_MAX - 1;UINT32_MAX - 1with its stride wrapping; 65522x43692; an output mapping one byte short or with no data; a stride below the width; and the 128 KiB mapping for the wrapping frame.(uint32_t)65536 * 43692 * 3 / 2= 131072.tests/test_formats.c: exit 0.