From 289782c6f3b6695c69a6133dd39b8b7650496466 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 14 Oct 2026 01:49:09 -0500 Subject: [PATCH] Fix possible UB shift in bs_write_u() for large values of n --- h264bitstream/bs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h264bitstream/bs.h b/h264bitstream/bs.h index abd6c412..fc8fbf44 100644 --- a/h264bitstream/bs.h +++ b/h264bitstream/bs.h @@ -208,7 +208,7 @@ static inline void bs_write_u(bs_t* b, int n, uint32_t v) int i; for (i = 0; i < n; i++) { - bs_write_u1(b, (v >> ( n - i - 1 ))&0x01 ); + bs_write_u1(b, (n - i - 1 >= 32) ? 0 : ((v >> ( n - i - 1 ))&0x01) ); } }