comparison mpeg12.c @ 241:4bb6289eff93 libavcodec

avoid overflow of picturenumber*fps*10000 bug found by Lennert Buytenhek <buytenh@gnu.org>
author michaelni
date Mon, 18 Feb 2002 01:58:00 +0000
parents e3e0094cb5c9
children e10840e4f773
comparison
equal deleted inserted replaced
240:e3e0094cb5c9 241:4bb6289eff93
104 put_header(s, GOP_START_CODE); 104 put_header(s, GOP_START_CODE);
105 put_bits(&s->pb, 1, 0); /* do drop frame */ 105 put_bits(&s->pb, 1, 0); /* do drop frame */
106 /* time code : we must convert from the real frame rate to a 106 /* time code : we must convert from the real frame rate to a
107 fake mpeg frame rate in case of low frame rate */ 107 fake mpeg frame rate in case of low frame rate */
108 fps = frame_rate_tab[s->frame_rate_index]; 108 fps = frame_rate_tab[s->frame_rate_index];
109 time_code = s->fake_picture_number * FRAME_RATE_BASE; 109 time_code = (INT64)s->fake_picture_number * FRAME_RATE_BASE;
110 s->gop_picture_number = s->fake_picture_number; 110 s->gop_picture_number = s->fake_picture_number;
111 put_bits(&s->pb, 5, (UINT32)((time_code / (fps * 3600)) % 24)); 111 put_bits(&s->pb, 5, (UINT32)((time_code / (fps * 3600)) % 24));
112 put_bits(&s->pb, 6, (UINT32)((time_code / (fps * 60)) % 60)); 112 put_bits(&s->pb, 6, (UINT32)((time_code / (fps * 60)) % 60));
113 put_bits(&s->pb, 1, 1); 113 put_bits(&s->pb, 1, 1);
114 put_bits(&s->pb, 6, (UINT32)((time_code / fps) % 60)); 114 put_bits(&s->pb, 6, (UINT32)((time_code / fps) % 60));
119 119
120 if (s->frame_rate < (24 * FRAME_RATE_BASE) && s->picture_number > 0) { 120 if (s->frame_rate < (24 * FRAME_RATE_BASE) && s->picture_number > 0) {
121 /* insert empty P pictures to slow down to the desired 121 /* insert empty P pictures to slow down to the desired
122 frame rate. Each fake pictures takes about 20 bytes */ 122 frame rate. Each fake pictures takes about 20 bytes */
123 fps = frame_rate_tab[s->frame_rate_index]; 123 fps = frame_rate_tab[s->frame_rate_index];
124 n = ((s->picture_number * fps) / s->frame_rate) - 1; 124 n = (((INT64)s->picture_number * fps) / s->frame_rate) - 1;
125 while (s->fake_picture_number < n) { 125 while (s->fake_picture_number < n) {
126 mpeg1_skip_picture(s, s->fake_picture_number - 126 mpeg1_skip_picture(s, s->fake_picture_number -
127 s->gop_picture_number); 127 s->gop_picture_number);
128 s->fake_picture_number++; 128 s->fake_picture_number++;
129 } 129 }