aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/shorten.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-09-12 13:30:44 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-09-12 13:31:59 +0200
commita44d35d90ffa0cfc3eb8a8a8fc6c20ffec4e90fe (patch)
tree2650f965bb85fc7e5955e40b250a8570b51057ea /libavcodec/shorten.c
parentaf539319af3a2c173e275fb927c7069e6b167114 (diff)
parent49568851bf1700e3d9ea9cda29208d0df3c2c38b (diff)
downloadffmpeg-a44d35d90ffa0cfc3eb8a8a8fc6c20ffec4e90fe.tar.gz
Merge commit '49568851bf1700e3d9ea9cda29208d0df3c2c38b'
* commit '49568851bf1700e3d9ea9cda29208d0df3c2c38b': shorten: Use a checked bytestream reader for the wave header Conflicts: libavcodec/shorten.c See: 5e9a56a0350c518cd4b38845aff49d41a9c952ae Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/shorten.c')
-rw-r--r--libavcodec/shorten.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index 3bba10c398..93959dc348 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -209,34 +209,36 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
{
int len, bps;
short wave_format;
- const uint8_t *end= header + header_size;
+ GetByteContext gb;
- if (bytestream_get_le32(&header) != MKTAG('R', 'I', 'F', 'F')) {
+ bytestream2_init(&gb, header, header_size);
+
+ if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
return AVERROR_INVALIDDATA;
}
- header += 4; /* chunk size */
+ bytestream2_skip(&gb, 4); /* chunk size */
- if (bytestream_get_le32(&header) != MKTAG('W', 'A', 'V', 'E')) {
+ if (bytestream2_get_le32(&gb) != MKTAG('W', 'A', 'V', 'E')) {
av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
return AVERROR_INVALIDDATA;
}
- while (bytestream_get_le32(&header) != MKTAG('f', 'm', 't', ' ')) {
- len = bytestream_get_le32(&header);
- if (len<0 || end - header - 8 < len)
+ while (bytestream2_get_le32(&gb) != MKTAG('f', 'm', 't', ' ')) {
+ len = bytestream2_get_le32(&gb);
+ if (len<0 || bytestream2_get_bytes_left(&gb) - 8 < len)
return AVERROR_INVALIDDATA;
- header += len;
+ bytestream2_skip(&gb, len);
}
- len = bytestream_get_le32(&header);
+ len = bytestream2_get_le32(&gb);
if (len < 16) {
av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n");
return AVERROR_INVALIDDATA;
}
- wave_format = bytestream_get_le16(&header);
+ wave_format = bytestream2_get_le16(&gb);
switch (wave_format) {
case WAVE_FORMAT_PCM:
@@ -246,11 +248,11 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
return AVERROR(ENOSYS);
}
- header += 2; // skip channels (already got from shorten header)
- avctx->sample_rate = bytestream_get_le32(&header);
- header += 4; // skip bit rate (represents original uncompressed bit rate)
- header += 2; // skip block align (not needed)
- bps = bytestream_get_le16(&header);
+ bytestream2_skip(&gb, 2); // skip channels (already got from shorten header)
+ avctx->sample_rate = bytestream2_get_le32(&gb);
+ bytestream2_skip(&gb, 4); // skip bit rate (represents original uncompressed bit rate)
+ bytestream2_skip(&gb, 2); // skip block align (not needed)
+ bps = bytestream2_get_le16(&gb);
avctx->bits_per_coded_sample = bps;
if (bps != 16 && bps != 8) {