media: v4l2-h264: Fix memcmp() size in B1 reference list comparison
PATCH v2 1/1 media: v4l2-h264: Fix memcmp() size in B1 reference list comparison
In v4l2_h264_build_b_ref_lists(), the B0/B1 list equality check passes the entry count builder->num_valid to memcmp() instead of a byte size. Since struct v4l2_h264_reference is two bytes (fields and index), only half of each list is compared, so distinct lists can be wrongly treated as equal and trigger an incorrect swap(b1_reflist[0], b1_reflist[1]).
Change the memcmp() size argument to sizeof(b1_reflist[0]) * builder->num_valid so that the full byte length of both reference lists is compared.
---
Changes in v2:
- Use sizeof(b1_reflist[0]) * builder->num_valid for the memcmp() size to match the style of the memcpy() calls in the same function.
--- drivers/media/v4l2-core/v4l2-h264.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-h264.c +2 -1
@@ -440,7 +440,8 @@ v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder, }if (builder->num_valid >1 && - !memcmp (b1_reflist, b0_reflist, builder->num_valid)) + !memcmp (b1_reflist, b0_reflist, + sizeof(b1_reflist[0]) * builder->num_valid)))swap (b1_reflist[0 ], b1_reflist[1 ]);print_ref_list_b (builder, b0_reflist,0 );
Signature · 1 line
2.43.0
Hi,
Le lundi 31 août 2026 à 13:54 +0800, Haotian Zhang a écrit :
Quoted 27 lines
In
v4l2_h264_build_b_ref_lists(), the B0/B1 list equality check passes the entry countbuilder->num_validtomemcmp()instead of a byte size. Since structv4l2_h264_referenceis two bytes (fields and index), only half of each list is compared, so distinct lists can be wrongly treated as equal and trigger an incorrectswap(b1_reflist[0], b1_reflist[1]).Change the
memcmp()size argument tosizeof(b1_reflist[0])*builder->num_validso that the full byte length of both reference lists is compared.Fixes 624922a2739b ("media: v4l2-core: Add helpers to build the H264 P/B0/B1 reflists")Suggested-by Nicolas Dufresne <[email protected]>Signed-off-by Haotian Zhang <[email protected]>---
Changes in v2:
- Usesizeof(b1_reflist[0])*builder->num_validfor thememcmp()size to match the style of thememcpy()calls in the same function.--- drivers/media/v4l2-core/v4l2-h264.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/media/v4l2-core/v4l2-h264.c +0
-0
drivers/media/v4l2-core/v4l2-h264.c v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder, · line 444
Quoted 6 lines
drivers/media/v4l2-core/v4l2-h264.c +2
-1@@ -440,7 +440,8 @@ v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder, }if (builder->num_valid >1 && - !memcmp (b1_reflist, b0_reflist, builder->num_valid)) + !memcmp (b1_reflist, b0_reflist, + sizeof(b1_reflist[0]) * builder->num_valid)))
I don't build test my suggestions, I expect submitter to do that before sending. There is too many closing parathensis here.
Nicolas
Quoted 3 lines
drivers/media/v4l2-core/v4l2-h264.c +0
-0swap (b1_reflist[0 ], b1_reflist[1 ]);print_ref_list_b (builder, b0_reflist,0 );