Commit bcc722c29d for ffmpeg
commit bcc722c29dc4b3ac3a7b32baa1907361b7120693
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Sun Nov 22 19:10:09 2026 -0500
avformat/ogg/muxer: compute the Theora granule masks in 64 bits
KFGSHIFT can be 31, which overflows a 32-bit shift of 1. Every frame
then exceeded the frame count limit and was marked as a keyframe.
diff --git a/libavformat/ogg/muxer.c b/libavformat/ogg/muxer.c
index 98a49fbd53..0c1fa017b2 100644
--- a/libavformat/ogg/muxer.c
+++ b/libavformat/ogg/muxer.c
@@ -148,7 +148,7 @@ static void ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
static int ogg_key_granule(OGGStreamContext *oggstream, int64_t granule)
{
- return (oggstream->kfgshift && !(granule & ((1<<oggstream->kfgshift)-1))) ||
+ return (oggstream->kfgshift && !(granule & ((INT64_C(1)<<oggstream->kfgshift)-1))) ||
(oggstream->isvp8 && !((granule >> 3) & 0x07ffffff));
}
@@ -156,7 +156,7 @@ static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t gra
{
if (oggstream->kfgshift)
return (granule>>oggstream->kfgshift) +
- (granule & ((1<<oggstream->kfgshift)-1));
+ (granule & ((INT64_C(1)<<oggstream->kfgshift)-1));
else if (oggstream->isvp8)
return granule >> 32;
else
@@ -838,7 +838,7 @@ static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
oggstream->last_kf_pts = pts;
pframe_count = pts - oggstream->last_kf_pts;
// prevent frame count from overflow if key frame flag is not set
- if (pframe_count >= (1<<oggstream->kfgshift)) {
+ if (pframe_count >= (INT64_C(1)<<oggstream->kfgshift)) {
oggstream->last_kf_pts += pframe_count;
pframe_count = 0;
}