1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avformat/matroskadec: Beautify matroska_parse_laces()

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2020-05-20 21:24:34 +02:00
parent 2a3bbc0086
commit 1fd8528c4e

View File

@ -3037,9 +3037,9 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
if (size <= 0) if (size <= 0)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
*laces = *data + 1; *laces = *data + 1;
data += 1; data += 1;
size -= 1; size -= 1;
switch (type) { switch (type) {
case 0x1: /* Xiph lacing */ case 0x1: /* Xiph lacing */
@ -3049,31 +3049,26 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
for (n = 0; n < *laces - 1; n++) { for (n = 0; n < *laces - 1; n++) {
lace_size[n] = 0; lace_size[n] = 0;
while (1) { do {
if (size <= total) { if (size <= total)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
}
temp = *data; temp = *data;
total += temp; total += temp;
lace_size[n] += temp; lace_size[n] += temp;
data += 1; data += 1;
size -= 1; size -= 1;
if (temp != 0xff) } while (temp == 0xff);
break;
}
} }
if (size < total) { if (size < total)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
}
lace_size[n] = size - total; lace_size[n] = size - total;
break; break;
} }
case 0x2: /* fixed-size lacing */ case 0x2: /* fixed-size lacing */
if (size % (*laces)) { if (size % (*laces))
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
}
for (n = 0; n < *laces; n++) for (n = 0; n < *laces; n++)
lace_size[n] = size / *laces; lace_size[n] = size / *laces;
break; break;
@ -3109,15 +3104,15 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
} }
data += offset; data += offset;
size -= offset; size -= offset;
if (size < total) { if (size < total)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
}
lace_size[*laces - 1] = size - total; lace_size[*laces - 1] = size - total;
break; break;
} }
} }
*buf = data; *buf = data;
return 0; return 0;
} }