h264bitwriter: Add check for data size to avoid overflow

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7547>
This commit is contained in:
He Junyan 2024-09-07 10:45:09 +08:00 committed by GStreamer Marge Bot
parent b427f33818
commit 2652467d7c

View file

@ -1571,6 +1571,7 @@ gst_h264_bit_writer_convert_to_nal (guint nal_prefix_size, gboolean packetized,
GST_H264_BIT_WRITER_ERROR); GST_H264_BIT_WRITER_ERROR);
g_return_val_if_fail (raw_data != NULL, GST_H264_BIT_WRITER_ERROR); g_return_val_if_fail (raw_data != NULL, GST_H264_BIT_WRITER_ERROR);
g_return_val_if_fail (raw_size > 0, GST_H264_BIT_WRITER_ERROR); g_return_val_if_fail (raw_size > 0, GST_H264_BIT_WRITER_ERROR);
g_return_val_if_fail (raw_size / 8 <= G_MAXUINT, GST_H264_BIT_WRITER_ERROR);
g_return_val_if_fail (nal_data != NULL, GST_H264_BIT_WRITER_ERROR); g_return_val_if_fail (nal_data != NULL, GST_H264_BIT_WRITER_ERROR);
g_return_val_if_fail (nal_size != NULL, GST_H264_BIT_WRITER_ERROR); g_return_val_if_fail (nal_size != NULL, GST_H264_BIT_WRITER_ERROR);
g_return_val_if_fail (*nal_size > 0, GST_H264_BIT_WRITER_ERROR); g_return_val_if_fail (*nal_size > 0, GST_H264_BIT_WRITER_ERROR);
@ -1598,7 +1599,7 @@ gst_h264_bit_writer_convert_to_nal (guint nal_prefix_size, gboolean packetized,
nal_writer_init (&nw, nal_prefix_size, packetized); nal_writer_init (&nw, nal_prefix_size, packetized);
if (!nal_writer_put_bytes (&nw, raw_data, raw_size / 8)) if (!nal_writer_put_bytes (&nw, raw_data, (guint) (raw_size / 8)))
goto error; goto error;
if (raw_size % 8) { if (raw_size % 8) {