mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-13 18:40:03 +01:00
Merge commit '90bc423212396e96a02edc1118982ab7f7766a63'
* commit '90bc423212396e96a02edc1118982ab7f7766a63': mov: Wrap stsc index and count compare in a separate function The mov_stsc_index_valid() function is replaced with a macro to prevent signdness issues (index is not always signed, and count is always unsigned currently). The comparison is also adjusted to reduce the risk of overflows. Merged-by: Clément Bœsch <u@pkh.me>
This commit is contained in:
@@ -2432,12 +2432,14 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define mov_stsc_index_valid(index, count) ((index) < (count) - 1)
|
||||||
|
|
||||||
/* Compute the samples value for the stsc entry at the given index. */
|
/* Compute the samples value for the stsc entry at the given index. */
|
||||||
static inline int mov_get_stsc_samples(MOVStreamContext *sc, int index)
|
static inline int mov_get_stsc_samples(MOVStreamContext *sc, int index)
|
||||||
{
|
{
|
||||||
int chunk_count;
|
int chunk_count;
|
||||||
|
|
||||||
if (index < sc->stsc_count - 1)
|
if (mov_stsc_index_valid(index, sc->stsc_count))
|
||||||
chunk_count = sc->stsc_data[index + 1].first - sc->stsc_data[index].first;
|
chunk_count = sc->stsc_data[index + 1].first - sc->stsc_data[index].first;
|
||||||
else
|
else
|
||||||
chunk_count = sc->chunk_count - (sc->stsc_data[index].first - 1);
|
chunk_count = sc->chunk_count - (sc->stsc_data[index].first - 1);
|
||||||
@@ -3353,7 +3355,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
|||||||
for (i = 0; i < sc->chunk_count; i++) {
|
for (i = 0; i < sc->chunk_count; i++) {
|
||||||
int64_t next_offset = i+1 < sc->chunk_count ? sc->chunk_offsets[i+1] : INT64_MAX;
|
int64_t next_offset = i+1 < sc->chunk_count ? sc->chunk_offsets[i+1] : INT64_MAX;
|
||||||
current_offset = sc->chunk_offsets[i];
|
current_offset = sc->chunk_offsets[i];
|
||||||
while (stsc_index + 1 < sc->stsc_count &&
|
while (mov_stsc_index_valid(stsc_index, sc->stsc_count) &&
|
||||||
i + 1 == sc->stsc_data[stsc_index + 1].first)
|
i + 1 == sc->stsc_data[stsc_index + 1].first)
|
||||||
stsc_index++;
|
stsc_index++;
|
||||||
|
|
||||||
@@ -3476,7 +3478,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
|||||||
count = (chunk_samples+1023) / 1024;
|
count = (chunk_samples+1023) / 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i < sc->stsc_count - 1)
|
if (mov_stsc_index_valid(i, sc->stsc_count))
|
||||||
chunk_count = sc->stsc_data[i+1].first - sc->stsc_data[i].first;
|
chunk_count = sc->stsc_data[i+1].first - sc->stsc_data[i].first;
|
||||||
else
|
else
|
||||||
chunk_count = sc->chunk_count - (sc->stsc_data[i].first - 1);
|
chunk_count = sc->chunk_count - (sc->stsc_data[i].first - 1);
|
||||||
@@ -3497,7 +3499,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
|
|||||||
// populate index
|
// populate index
|
||||||
for (i = 0; i < sc->chunk_count; i++) {
|
for (i = 0; i < sc->chunk_count; i++) {
|
||||||
current_offset = sc->chunk_offsets[i];
|
current_offset = sc->chunk_offsets[i];
|
||||||
if (stsc_index + 1 < sc->stsc_count &&
|
if (mov_stsc_index_valid(stsc_index, sc->stsc_count) &&
|
||||||
i + 1 == sc->stsc_data[stsc_index + 1].first)
|
i + 1 == sc->stsc_data[stsc_index + 1].first)
|
||||||
stsc_index++;
|
stsc_index++;
|
||||||
chunk_samples = sc->stsc_data[stsc_index].count;
|
chunk_samples = sc->stsc_data[stsc_index].count;
|
||||||
@@ -6265,7 +6267,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
/* Keep track of the stsc index for the given sample, then check
|
/* Keep track of the stsc index for the given sample, then check
|
||||||
* if the stsd index is different from the last used one. */
|
* if the stsd index is different from the last used one. */
|
||||||
sc->stsc_sample++;
|
sc->stsc_sample++;
|
||||||
if (sc->stsc_index < sc->stsc_count - 1 &&
|
if (mov_stsc_index_valid(sc->stsc_index, sc->stsc_count) &&
|
||||||
mov_get_stsc_samples(sc, sc->stsc_index) == sc->stsc_sample) {
|
mov_get_stsc_samples(sc, sc->stsc_index) == sc->stsc_sample) {
|
||||||
sc->stsc_index++;
|
sc->stsc_index++;
|
||||||
sc->stsc_sample = 0;
|
sc->stsc_sample = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user