1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avcodec/pnmdec: Fix misaligned reads

Found-by: "Steinar H. Gunderson" <steinar+ffmpeg@gunderson.no>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit ea28ce9bc1)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2020-07-03 23:55:50 +02:00
parent 347bcf6054
commit 34f9c735ad

View File

@ -172,7 +172,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
} else if (upgrade == 2) {
unsigned int j, v, f = (65535 * 32768 + s->maxval / 2) / s->maxval;
for (j = 0; j < n / 2; j++) {
v = av_be2ne16(((uint16_t *)s->bytestream)[j]);
v = AV_RB16(s->bytestream + 2*j);
((uint16_t *)ptr)[j] = (v * f + 16384) >> 15;
}
}
@ -226,7 +226,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
return AVERROR_INVALIDDATA;
for (i = 0; i < avctx->height; i++) {
for (j = 0; j < n / 2; j++) {
v = av_be2ne16(((uint16_t *)s->bytestream)[j]);
v = AV_RB16(s->bytestream + 2*j);
((uint16_t *)ptr)[j] = (v * f + 16384) >> 15;
}
s->bytestream += n;
@ -238,13 +238,13 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
h = avctx->height >> 1;
for (i = 0; i < h; i++) {
for (j = 0; j < n / 2; j++) {
v = av_be2ne16(((uint16_t *)s->bytestream)[j]);
v = AV_RB16(s->bytestream + 2*j);
ptr1[j] = (v * f + 16384) >> 15;
}
s->bytestream += n;
for (j = 0; j < n / 2; j++) {
v = av_be2ne16(((uint16_t *)s->bytestream)[j]);
v = AV_RB16(s->bytestream + 2*j);
ptr2[j] = (v * f + 16384) >> 15;
}
s->bytestream += n;