diff mbox

[FFmpeg-devel] lavc/qtrle: Do not use aligned writes for odd addresses.

Message ID CAB0OVGoXxGQBMnebekqSF1xjXJLkjBt1VwcB=qC7CpyipxTSiA@mail.gmail.com
State Superseded
Headers show

Commit Message

Carl Eugen Hoyos March 14, 2019, 11:05 p.m. UTC
Hi!

Attached patch fixes the qtrle crash on sparc for me.

Please comment, Carl Eugen

Comments

Hendrik Leppkes March 14, 2019, 11:13 p.m. UTC | #1
On Fri, Mar 15, 2019 at 12:05 AM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>
> Hi!
>
> Attached patch fixes the qtrle crash on sparc for me.
>

It should be fine in cases where the pointer is being incremented by
an aligned amount, ie. writing 32 and incrementing by 4, or 64 and 8,
etc.
Are all of those required to pass, or only the ones on "odd"
increments like 3 for 24-bit RGB? (In fact, those "odd" ones are the
ones that are new recently)

- Hendrik
diff mbox

Patch

From a94d32d63cff248d2eb633b162e9e4d4f7234ee5 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Fri, 15 Mar 2019 00:02:48 +0100
Subject: [PATCH] lavc/qtrle: Do not used aligned writes for odd addresses.

pixel_ptr can be 3.
Fixes crashes on systems that do not allow unaligned access.
---
 libavcodec/qtrle.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index a744d7b..1351532 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -325,7 +325,7 @@  static void qtrle_decode_24bpp(QtrleContext *s, int row_ptr, int lines_to_change
                 CHECK_PIXEL_PTR(rle_code * 3);
 
                 while (rle_code--) {
-                    AV_WN16A(rgb + pixel_ptr, rg);
+                    AV_WN16(rgb + pixel_ptr, rg);
                     rgb[pixel_ptr + 2] = b;
                     pixel_ptr += 3;
                 }
@@ -335,13 +335,13 @@  static void qtrle_decode_24bpp(QtrleContext *s, int row_ptr, int lines_to_change
                 rle_code_half = rle_code / 2;
 
                 while (rle_code_half--) { /* copy 2 raw rgb value at the same time */
-                    AV_WN32A(rgb + pixel_ptr, bytestream2_get_ne32(&s->g)); /* rgbr */
-                    AV_WN16A(rgb + pixel_ptr + 4, bytestream2_get_ne16(&s->g)); /* rgbr */
+                    AV_WN32(rgb + pixel_ptr, bytestream2_get_ne32(&s->g)); /* rgbr */
+                    AV_WN16(rgb + pixel_ptr + 4, bytestream2_get_ne16(&s->g)); /* rgbr */
                     pixel_ptr += 6;
                 }
 
                 if (rle_code % 2 != 0){ /* not even raw value */
-                    AV_WN16A(rgb + pixel_ptr, bytestream2_get_ne16(&s->g));
+                    AV_WN16(rgb + pixel_ptr, bytestream2_get_ne16(&s->g));
                     rgb[pixel_ptr + 2] = bytestream2_get_byte(&s->g);
                     pixel_ptr += 3;
                 }
@@ -379,7 +379,7 @@  static void qtrle_decode_32bpp(QtrleContext *s, int row_ptr, int lines_to_change
                 CHECK_PIXEL_PTR(rle_code * 4);
 
                 while (rle_code--) {
-                    AV_WN32A(rgb + pixel_ptr, argb);
+                    AV_WN32(rgb + pixel_ptr, argb);
                     pixel_ptr += 4;
                 }
             } else {
@@ -388,12 +388,12 @@  static void qtrle_decode_32bpp(QtrleContext *s, int row_ptr, int lines_to_change
                 /* copy pixels directly to output */
                 rle_code_half = rle_code / 2;
                 while (rle_code_half--) { /* copy 2 argb raw value at the same time */
-                    AV_WN64A(rgb + pixel_ptr, bytestream2_get_ne64(&s->g));
+                    AV_WN64(rgb + pixel_ptr, bytestream2_get_ne64(&s->g));
                     pixel_ptr += 8;
                 }
 
                 if (rle_code % 2 != 0){ /* not even raw value */
-                    AV_WN32A(rgb + pixel_ptr, bytestream2_get_ne32(&s->g));
+                    AV_WN32(rgb + pixel_ptr, bytestream2_get_ne32(&s->g));
                     pixel_ptr += 4;
                 }
             }
-- 
1.7.10.4