---
 libavcodec/sunrastenc.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavcodec/sunrastenc.c b/libavcodec/sunrastenc.c
index a9b4749..d8035a5 100644
--- a/libavcodec/sunrastenc.c
+++ b/libavcodec/sunrastenc.c
@@ -83,15 +83,21 @@ static void sunrast_image_write_image(AVCodecContext *avctx,
      if (s->type == RT_BYTE_ENCODED) {
         uint8_t value, value2;
         int run;
-        const uint8_t *end = pixels + avctx->height * linesize;
+        const uint8_t *start = pixels;
+        const uint8_t *end   = pixels + avctx->height * abs(linesize);
+
+        if (linesize < 0) {
+            start = pixels + avctx->height * linesize;
+            end   = start  + avctx->height * (abs(linesize) + 1);
+        }
 
         ptr = pixels;
 
-#define GET_VALUE ptr >= end ? 0 : x >= len ? ptr[len-1] : ptr[x]
+#define GET_VALUE ptr >= end || ptr < start ? 0 : x >= len ? ptr[len-1] : 
ptr[x]
 
         x = 0;
         value2 = GET_VALUE;
-        while (ptr < end) {
+        while (ptr < end && ptr >= start) {
             run = 1;
             value = value2;
             x++;
@@ -101,7 +107,7 @@ static void sunrast_image_write_image(AVCodecContext *avctx,
             }
 
             value2 = GET_VALUE;
-            while (value2 == value && run < 256 && ptr < end) {
+            while (value2 == value && run < 256 && ptr < end && ptr >= start) {
                 x++;
                 run++;
                 if (x >= alen) {
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to