From patchwork Fri Jul 3 22:15:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 20790 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0352E44AA1E for ; Sat, 4 Jul 2020 01:16:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CE431688344; Sat, 4 Jul 2020 01:16:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-2.mx.upcmail.net (vie01a-dmta-pe05-2.mx.upcmail.net [84.116.36.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 859A7688344 for ; Sat, 4 Jul 2020 01:16:35 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1jrTz1-0006ui-0S for ffmpeg-devel@ffmpeg.org; Sat, 04 Jul 2020 00:16:35 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id rTy2jVKe96Jy6rTy2jR5sR; Sat, 04 Jul 2020 00:15:35 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=GKl27dFK c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=wpzw1knUDiPKJzn23SEA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 4 Jul 2020 00:15:34 +0200 Message-Id: <20200703221534.9205-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfMu1LIr+lqk/Z+bogf5P8HeY/rMRrLYH3GmBnYXT1CpN5RSd9NQ8xLuUVeJtKoKn7+kwP3CrZ+TKrK/5Tqf2k9jiHwur/02L86esHOeotl6ZT9dQKKW/ /hELeqBwnJ6bnUtvioOkx4iyTIOT7CxNtcjCDjd4v5f1a+AQq8/Dp2Lj Subject: [FFmpeg-devel] [PATCH] avcodec/pnmdec: Fix misaligned reads X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Found-by: "Steinar H. Gunderson" Signed-off-by: Michael Niedermayer --- libavcodec/pnmdec.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index 05bd11b147..9add5cfc84 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -173,7 +173,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; } } @@ -227,7 +227,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; @@ -239,13 +239,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; @@ -267,9 +267,9 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, b = (float *)p->data[1]; for (int i = 0; i < avctx->height; i++) { for (int j = 0; j < avctx->width; j++) { - r[j] = av_int2float(av_le2ne32(((uint32_t *)s->bytestream)[0])) * scale; - g[j] = av_int2float(av_le2ne32(((uint32_t *)s->bytestream)[4])) * scale; - b[j] = av_int2float(av_le2ne32(((uint32_t *)s->bytestream)[8])) * scale; + r[j] = av_int2float(AV_RL32(s->bytestream+0)) * scale; + g[j] = av_int2float(AV_RL32(s->bytestream+4)) * scale; + b[j] = av_int2float(AV_RL32(s->bytestream+8)) * scale; s->bytestream += 12; } @@ -285,9 +285,9 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, b = (float *)p->data[1]; for (int i = 0; i < avctx->height; i++) { for (int j = 0; j < avctx->width; j++) { - r[j] = av_int2float(av_be2ne32(((uint32_t *)s->bytestream)[0])) * scale; - g[j] = av_int2float(av_be2ne32(((uint32_t *)s->bytestream)[4])) * scale; - b[j] = av_int2float(av_be2ne32(((uint32_t *)s->bytestream)[8])) * scale; + r[j] = av_int2float(AV_RB32(s->bytestream+0)) * scale; + g[j] = av_int2float(AV_RB32(s->bytestream+4)) * scale; + b[j] = av_int2float(AV_RB32(s->bytestream+8)) * scale; s->bytestream += 12; }