diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index d5fba7e..fca7922 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -530,6 +530,16 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
             src += width;
             break;
         case TIFF_PACKBITS:
+            if (s->fill_order) {
+                int i;
+                av_fast_padded_malloc(&s->deinvert_buf, &s->deinvert_buf_size, size);
+                 if (!s->deinvert_buf)
+                     return AVERROR(ENOMEM);
+                 for (i = 0; i < width; i++)
+                     s->deinvert_buf[i] = ff_reverse[src[i]];
+                 src = s->deinvert_buf;
+                 ssrc = src;
+            }
             for (pixels = 0; pixels < width;) {
                 if (ssrc + size - src < 2) {
                     av_log(s->avctx, AV_LOG_ERROR, "Read went out of bounds\n");
